[R-sig-Geo] Read raster data in Big Endian (Motorola) byteorder on Little Endian (Intel) system
O'Hanlon, Simon J
simon.ohanlon at imperial.ac.uk
Tue Jul 17 19:58:03 CEST 2012
For anyone who is working with the Hydro 1K dataset from the USGS EROS centre you might find this useful as this is the data I had a problem getting read in correctly. But it was not due to byte ordering issues as I initially thought (see below). It was simply because the GDAL driver was not recognising that the data was signed integer rather than unsigned.
After reading some documentation on the gdal website and playing around I found all I needed to do was add a PIXELTYPE argument to my .HDR file and set the value to SIGNEDINT:
And after reading in the same data I now I get the following:
getValues(mydata)
min(mydata)
-9999
max(mydata)
2376
Which is what it is supposed to be according to the data documentation and my plots look correct now.
Hope that helps someone in the future avoid the nasty mistake I nearly made (analysing totally incorrect values!).
Simon
-----Original Message-----
From: r-sig-geo-bounces at r-project.org [mailto:r-sig-geo-bounces at r-project.org] On Behalf Of O'Hanlon, Simon J
Sent: 17 July 2012 17:47
To: R-sig-Geo at r-project.org
Subject: [R-sig-Geo] Read raster data in Big Endian (Motorola) byteorder on Little Endian (Intel) system
Dear all,
I am working with some raster data (.bil format), with values stored in big endian byteorder. The info in the associated .hdr file is:
BYTEORDER M
LAYOUT BIL
NROWS 9194
NCOLS 8736
NBANDS 1
NBITS 16
BANDROWBYTES 17472
TOTALROWBYTES 17472
BANDGAPBYTES 0
When I read in 'mydata' using raster I see that it correctly states the min (-9999) and max (2376) values of the data (I assume from the .stx file since I believe the values are not actually read to memory at this stage?). However when I do str(mydata) I see that @file at byteorder slot is "little" and if I try:
values <- getValues(mydata)
min(values)
2
max(values)
55537
And most weirdly if I do:
summary(values)
Min. 1st Qu. Median Mean 3rd Qu. Max.
2 757 55540 35030 55540 55540
Does anyone know if/how I can specify the byteorder as Big Endian to the rgdal driver/raster function? I have tried changing BYTEORDER in the .hdr file to "big", but it does not work.
Thanks,
Simon
_______________________________________________
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