[R-sig-Geo] rgdal to gif: HELP!!!

Tomislav Hengl hengl at spatial-analyst.net
Tue Mar 15 14:47:59 CET 2011


I recommend using the caTools package for this.

Here is a peace of code I used to write some GIFs with color legend. I 
hope it is self-explanatory :)

# make a color palette:
 > col.pal <- c(grey(1), grey(0.6), grey(0), rep(grey(0), 256-3))

# import DEM to R:
 > dem <- readGDAL("dem.sdat")
# convert to 0:255 numbers:
 > dem$mask <- ifelse(!is.na(dem$band1), 2, ifelse(dem$band1 > 0, 1, 0))
 > write.gif(image=t(as.matrix(dem["mask"])), filename=paste(getwd(), 
"/", "dem_mask_1.gif", sep=""), col=col.pal)

# for scripting possibilities with ImageMagick see 
[http://www.imagemagick.org/Usage/anim_basics/];
 > system("C:\\PROGRA~1\\IMAGEM~1\\convert -delay 80 -loop 0 
*_mask_*.gif  mask_ani.gif")
 > system("C:\\PROGRA~1\\IMAGEM~1\\identify mask_ani.gif")

Here is a result:

http://bioislands.org/sites/default/files/images/mask_ani.gif

HTH,

T. Hengl
http://www.wewur.wur.nl/popups/vcard.aspx?id=HENGL001



Op 15-3-2011 10:14, Lorenzo Alfieri schreef:
>
> Dear all,
>
> I'm new to this forum.
>
> I'm desperately looking for help, as I'm stuck with a problem and I can't find any solution.
>
> I'd like to open a raster map (for example with rgdal it is read as a
> SpatialGridDataFrame) and then save it as a gif image with a specific
> color palette.
>
> I can't find the way to specify the color, so I can only create greyscale images.
>
> It sounds simple but nothing seems to work.
>
> I've been trying with:
>
>
>
> Kp1P<- readGDAL(mymap)
>
> writeGDAL(Kp1P,"myGIFmap.gif",drivername="gif",col=colmed)
>
>
>
> but col is not an option in writeGDAL command
>
>
>
> I need to specify this colors:
>
> colmed<-c(rep(rgb(255/255, 204/255, 204/255),10),rep(rgb(255/255,
> 184/255, 176/255),10),rep(rgb(255/255, 164/255,
> 176/255),10),rep(rgb(255/255, 144/255, 125/255),10),
>
>    rep(rgb(250/255, 125/255, 102/255),10),rep(rgb(247/255, 104/255,
> 79/255),10),rep(rgb(242/255, 85/255, 61/255),10),rep(rgb(235/255,
> 65/255, 42/255),10),
>
>    rep(rgb(227/255, 40/255, 23/255),10),rep(rgb(219/255, 0/255, 0/255),10))
>
>
>
> HELP!
>
>
>
> Lorenzo
> 				 		 	   		
> 	[[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo



More information about the R-sig-Geo mailing list