[R-sig-Geo] Rgdal and unsigned integers

Robert J. Hijmans r.hijmans at gmail.com
Fri Aug 21 00:52:16 CEST 2009


Jonathan,

I used the file you send me. This shows that the problem is already
present in rgdal (i.e. before it gets passed to raster)

> x <- readGDAL("stand_bm.gis")
stand_bm.gis has GDAL driver LAN
and has 839 rows and 1758 columns
> summary(x)
(...)
Data attributes:
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max.
 -32140       0       0    8316   19180   29620
>

I opened the file in ArcMap, saved it to a esri grid and read it into R

> stndesri <- raster("esri_stand", values = T)

> stnd <- raster("stand_bm.gis", values = T)

I adjusted the adjustment I send before
> stnd[stnd < 0] <- stnd[stnd < 0] + 65536

and these look good:

> stnd
class       : RasterLayer
filename    :
nrow        : 839
ncol        : 1758
ncells      : 1474962
min value   : 0
max value   : 48499   <--- same is gdal
(...)

the values of the two files are the same:
> dif <- stnd - stndesri

> summary(dif)
Values
Min.    0
1st Qu. 0
Median  0
Mean    0
3rd Qu. 0
Max.    0


The values are still very high in some places, but they should be,
that's what caused the problem to begin with. Whether these high
values are meaningful is another matter; but that could be caused by
LANDIS if that's what you are using.

Apparently something needs to be fixed in rgdal as Barry showed that
gdal gets the right values; it seems somewhere along the line the
INT16 is interpreted as signed, whereas it should be unsigned.

Best,
Robert

On Thu, Aug 20, 2009 at 2:44 PM, Barry
Rowlingson<b.rowlingson at lancaster.ac.uk> wrote:
> On Thu, Aug 20, 2009 at 9:57 PM, Jonathan
> Thompson<jthomps at fas.harvard.edu> wrote:
>
>> gdalinfo:
>> Band 1 Block=1758x1 Type=Int16, ColorInterp=Undefined
>>  Min=0.000 Max=48499.000
>
>>> Arcgis:
>>> Pixel Type  = unsigned integer
>>> Pixel Depth = 16 bit
>
> Arcgis is saying 'unsigned integer' but gdalinfo says 'Int16'. But
> then gdalinfo says the max is 48499 - which shouldn't be possible with
> (signed) Int16 values (they go from -32k to +32k).
>
>  So something is very odd...
>
> Barry
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>



More information about the R-sig-Geo mailing list