[R-sig-Geo] get rgdal to read ENVI raster?

Roger Bivand Roger.Bivand at nhh.no
Wed Aug 8 14:26:00 CEST 2007


On Wed, 8 Aug 2007, Felix Andrews wrote:

> Thanks Michael
>
> The extension is "flt" (float type). This resulted in a sensible image:
>
> foo <- readBin("G:/Projects/Tuross/surface_files/rainfall_surface/year2000/rainGrid_20001.flt",
> "double", n=200*200, size=4, endian="little")
> foo[foo==-9999] <- NA
> range(foo, finite=T)
> # 18.83187 80.23850
> image(matrix(foo, ncol=200))
> # sensible image, but flipped vertically I think
>
> This is what GDAL does:
>
> grid1 <- readGDAL("G:/Projects/Tuross/surface_files/rainfall_surface/year2000/rainGrid_20001.flt")
> # G:/Projects/Tuross/surface_files/rainfall_surface/year2000/rainGrid_20001.flt
> has GDAL driver EHdr
> # and has 200 rows and 200 columns
> # Closing GDAL dataset handle 0x02248358...  destroyed ... done.
> str(grid1 at data[[1]])
> # int [1:40000] 118 215 97 66 180 213 96 66 23 133 ...
>
> So the problem is that it thinks it is an integer type, whereas in
> fact it is a 4-byte float type.
>
> As a temporary hack, maybe I can use GDAL to import it, then just
> replace the @data slot with the correct numeric data.

I think you'll find that the data are integer - the rgdal code simply 
calls GDAL anyway (in your case on Windows freshly built GDAL 1.4.2). What 
does gdalinfo say about the file - I guess you have GDAL utilities 
installed on your system somewhere?

Roger

>
> Felix
>
> On 8/8/07, Michael Sumner <mdsumner at utas.edu.au> wrote:
>> Hi Felix, can you provide the file? The Ehdr driver is probably right, but
>> you might have some trouble with the values being interpreted.
>>
>> I'd like to see more information about the "just noise" data.
>>
>>
>> Cheers, Mike.
>>
>> -----Original Message-----
>> From: r-sig-geo-bounces at stat.math.ethz.ch
>> [mailto:r-sig-geo-bounces at stat.math.ethz.ch] On Behalf Of Felix Andrews
>> Sent: Wednesday, 8 August 2007 2:10 PM
>> To: r-sig-geo at stat.math.ethz.ch
>> Subject: Re: [R-sig-Geo] get rgdal to read ENVI raster?
>>
>> Sorry, I just realised that it is not an ENVI raster after all.
>> Looks like it is a "ESRI binary raster format" described at
>> http://coastwatch.noaa.gov/cw_form_br.html
>> and there does not seem to be a GDAL driver for it.
>>
>>
>> On 8/8/07, Felix Andrews <felix at nfrac.org> wrote:
>>> Hi,
>>>
>>> I am trying to use rgdal to read in an "ENVI .hdr labelled raster"
>>> --see http://www.gdal.org/frmt_various.html#ENVI
>>> but GDAL uses the wrong driver, "ESRI .hdr labelled"
>>> --see http://www.gdal.org/frmt_various.html#EHdr
>>>
>>> So the imported grid data is just noise.
>>> I can not figure out how to make GDAL/rgdal use the ENVI driver.
>>> Suggestions would be appreciated.
>>>
>>> The .hdr file contains:
>>> NCOLS      200
>>> NROWS      200
>>> XLLCORNER    148.50000000000
>>> YLLCORNER   -37.002500000000
>>> CELLSIZE    0.10000000000000E-01
>>> NODATA_VALUE   -9999.000
>>> BYTEORDER LSBFIRST
>>>
>>>
>>>> sessionInfo()
>>> R version 2.5.1 (2007-06-27)
>>> i386-pc-mingw32
>>>
>>> locale:
>>> LC_COLLATE=English_Australia.1252;LC_CTYPE=English_Australia.1252;LC_M
>>> ONETARY=English_Australia.1252;LC_NUMERIC=C;LC_TIME=English_Australia.
>>> 1252
>>>
>>> attached base packages:
>>> [1] "stats"     "graphics"  "grDevices" "utils"     "datasets"
>>> "methods"   "base"
>>>
>>> other attached packages:
>>>          rgdal       RArcInfo       maptools        foreign
>>>  sp    hydrosanity
>>>       "0.5-14"        "0.4-7"       "0.6-14"       "0.8-20"
>>> "0.9-14"       "0.8.57"
>>> plotAndPlayGTK    cairoDevice          RGtk2        lattice
>>>       "0.8.55"          "2.3"      "2.10.13"       "0.16-2"
>>>
>>>
>>> --
>>> Felix Andrews / °ÂʡΩ
>>> PhD candidate
>>> Integrated Catchment Assessment and Management Centre The Fenner
>>> School of Environment and Society The Australian National University
>>> (Building 48A), ACT 0200 Beijing Bag, Locked Bag 40, Kingston ACT 2604
>>> http://www.neurofractal.org/felix/
>>> voice:+86_1051404394 (in China)
>>> mobile:+86_13522529265 (in China)
>>> mobile:+61_410400963 (in Australia)
>>> xmpp:foolish.android at gmail.com
>>> 3358 543D AAC6 22C2 D336  80D9 360B 72DD 3E4C F5D8
>>>
>>
>>
>> --
>> Felix Andrews / °ÂʡΩ
>> PhD candidate
>> Integrated Catchment Assessment and Management Centre The Fenner School of
>> Environment and Society The Australian National University (Building 48A),
>> ACT 0200 Beijing Bag, Locked Bag 40, Kingston ACT 2604
>> http://www.neurofractal.org/felix/
>> voice:+86_1051404394 (in China)
>> mobile:+86_13522529265 (in China)
>> mobile:+61_410400963 (in Australia)
>> xmpp:foolish.android at gmail.com
>> 3358 543D AAC6 22C2 D336  80D9 360B 72DD 3E4C F5D8
>>
>> _______________________________________________
>> R-sig-Geo mailing list
>> R-sig-Geo at stat.math.ethz.ch
>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>
>>
>
>
> --
> Felix Andrews / °ÂʡΩ
> PhD candidate
> Integrated Catchment Assessment and Management Centre
> The Fenner School of Environment and Society
> The Australian National University (Building 48A), ACT 0200
> Beijing Bag, Locked Bag 40, Kingston ACT 2604
> http://www.neurofractal.org/felix/
> voice:+86_1051404394 (in China)
> mobile:+86_13522529265 (in China)
> mobile:+61_410400963 (in Australia)
> xmpp:foolish.android at gmail.com
> 3358 543D AAC6 22C2 D336  80D9 360B 72DD 3E4C F5D8
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>

-- 
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Helleveien 30, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: Roger.Bivand at nhh.no


More information about the R-sig-Geo mailing list