[R-sig-Geo] Convert some value to NaN (GeoTiff)

Carsten Neumann carstennh at aol.com
Wed Sep 14 15:35:43 CEST 2011


  Am 13.09.2011 06:32, schrieb Joel Risso:
> Dear All,
> I am new to spatial stats in R.
> I would be grateful if someone could help me in a script to convert some
> pixels' values (e.g. NoData, 0, etc.)  to NaN in a Geotiff input.
> Thank you,
> Joel
>
Dear Joel,

there is a quit simple way using raster package.

read GTiff:                a<-raster('H:\\example.tif')
setting NA values:   NAvalue(a)<-0 (here you define which value within 
your image should become a no data value)

or if you want a character string called "NaN" you can do:

d<-which (getValues(a) == 0)
a[d]<-"NaN"

I hope this helps.

Best regards

Carsten



More information about the R-sig-Geo mailing list