[R-sig-Geo] Raster Export as PNG

Alper Dinçer alperd.web at gmail.com
Sun Aug 16 20:56:03 CEST 2015


I'm very new to R and I'm trying to achieve something which may be easy but
I couldn't find any solutions for a week.

I read a GeoTiff file with Raster library and then crop with mask it with
shape file. Then I want to save it as a PNG file to show it on Google Maps
JS API, but it doesn't work due to inner margins when using plot().

This the code I'm working on :

xidw <- raster("output_6.tiff")

crs(xidw) <- "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs"

xidw.sub <- crop(xidw, extent(state))
xidw.sub <- mask(xidw.sub, state)

yidw <- projectRaster(xidw.sub, crs='+proj=merc +a=6378137 +b=6378137
+lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null

png(filename="output.png", width=800, height=500, bg="transparent")
plot(yidw, axes = F, box = F, legend = F)


Is there anything that I can get the PNG file with full extent of of my
cropped and masked raster?


Best wishes.


	[[alternative HTML version deleted]]

More information about the R-sig-Geo mailing list