How Does R read nodatavalue tags from a geotiff - R Raster package -


i running unusual outcome raster no data values in r. code below -- have raster has no data value import (-9999). qgis reads nodatavalue, arcgis too. r, when reads in geotiff, assigned nodata value -inf.

i don't know why. decided try make 1 scratch - , same result. wrong process? how can ensure r reads in nodatavalues properly?

note: example below created raster / geotiff. i'm importing geotiffs quite large produced organization. don't have control on how written ask them adjust tags if need be.

library(raster) #create raster matrix myraster1 <- raster(nrow=4, ncol=4)  #assign random data raster myraster1[]<- 1:ncell(myraster1)  myraster1[5] <- -9999  #ensure data have decimals myraster1[2] <- 34.5  #assign no data value raster myraster1@file@nodatavalue <- -9999  #make sure worked navalue(myraster1) myraster1@file@nodatavalue  #view attributes of raster myraster1   #write out raster #write geotiff - change overwrite=true overwrite=false if want make sure don't overwrite files! writeraster(myraster1,"newdel.tif","gtiff", overwrite=true)   #import raster newr <- raster("newdel.tif") newr@file@nodatavalue 

thank advice / explanation how r imports tags geotiff.

thank creating reproducible example, example created perhaps not helpful. assigning values slot (names behind @) not "legal". unless have advanced knowledge of raster objects, should use user-interface (functions, methods). so, never this:

myraster1@file@nodatavalue <- -9999 

the value in slot internal consumption only; , relevant objects values disk. likewise,

newr@file@nodatavalue # [1] -inf 

does not mean na values in "newdel.tif" stored way.

to set value when writing, use options available in writeraster.

now, problem seems have files values -9999 should considered na, , somehow not happen. odd work in qgis because same info , same underlying software used (gdal). here how can deal that:

create geotiff file values -9999 not recognized na

library(raster) r <- raster(nrow=5, ncol=5) values(r) <- 1:25 r[1:5] <- -9999 writeraster(r, 'test.tif', overwrite=true) 

your situation:

x <- raster('test.tif') plot(x) 

this fix it:

navalue(x) <- -9999 plot(x) 

Comments

Popular posts from this blog

java - Static nested class instance -

c# - Bluetooth LE CanUpdate Characteristic property -

JavaScript - Replace variable from string in all occurrences -