Skip to content
Prev 7828 / 29559 Next

Byte-value tif files not properly read by readGDAL

On Mon, 15 Mar 2010, reeves at nceas.ucsb.edu wrote:

            
Rick,

When you display the image, are the 128s in the locations of NODATA? (Read 
decimated to save time displaying - raster display should get faster in R 
2.11.* when Northern Hemisphere Spring comes). Much of what you provide 
below simply makes things harder to read, please only provide the output 
of sessionInfo(), and the message returned when rgdal is loaded. As 
table() of the band shows 0, 1, and 128 (included below), then 128 is 
likely to be the encoding used by the software creating the file for 
NODATA. As is clearly explained, rgdal does no more than interface the 
GDAL drivers for the GDAL version loaded - here the most recent.
........
......
.....

Well, if the values are 0, 1, and 128, they are unsigned, there are no 
negative values and Byte can use the 0:255 range, stored in R as integer, 
as you see here:
...........
No - in the absence of any input from the file metadata, the GDAL driver 
takes a guess at whether the Byte is signed or unsigned (GDALinfo() says 
"apparent"). The first guess is signed, but it reads unsigned, which is 
probably the intention in the creating software. Double-check with 
gdalinfo externally, but also search the Arc documentation to see how it 
is encoding NODATA, and whether you can encourage the creating software to 
declare the NODATA encoding so that the GDAL driver has a reasonable 
chance of guessing right.

Hope this helps,

Roger