[R-sig-Geo] Import BIL files in R, without the hdr file

Michael Sumner mdsumner at gmail.com
Wed Mar 28 02:53:31 CEST 2012


I think BANDROWBYTES and TOTALROWBYTES should both be 214 (107 * 2)
which is the number of columns times the 2 bytes for 16 NBITS.

You can infer what should happen from another example, which you can
do by something like this:

f <- system.file("pictures/erdas_spnad83.tif", package = "rgdal")[1]
g <- readGDAL(f)

## write out to EHdr format and read in the text
writeGDAL(g, "a.bil", "EHdr")
readLines("a.hdr")

Otherwise, refer to the GDAL page for this driver:
http://www.gdal.org/frmt_various.html#EHdr

Cheers, Mike.


On Wed, Mar 28, 2012 at 12:47 AM, Guillermo Olmedo
<folmedo at mendoza.inta.gov.ar> wrote:
> Hi list!
>
> I'm trying to import a BIL binary file into R. I've obtained the file
> running a soft called TIMESAT[1] but i only have the BIL file, not the HDR.
> Because i know how timesat generates the files I've the number of cols ands
> rows. Also i know the file its a 16 bit signed integer and little endian.
> I've followed the procedure here [2] and the info i know from the file to
> write my own hdr. But still doesnt work. Without the hdr file i still can
> import the bil file into ERDAS using import binary and it works flawlessly,
> but i don't want to use ERDAS.
>
> This is my hdr file:
> BYTEORDER      I
> LAYOUT         BIL
> NROWS          79
> NCOLS          107
> NBANDS         1
> NBITS          16
> BANDROWBYTES   80
> TOTALROWBYTES  80
> PIXELTYPE      INTEGER
> ULXMAP         0
> ULYMAP         0
> XDIM           107
> YDIM           79
>
> Maybe Bandrowbytes and totalrowbytes are wrong. At this moment the spatial
> location doesnt matters so i left ulxmap and ulymap as 0.
>
> My code is:
> BIL <- raster("amplitud.bil", native=T)
> dataType(bio) <- 'INT2S'
> plot(BIL)
>
> And the same result with:
> BIL <- raster(ncols=107, nrows= 79)
> BIN <- readBin("amplitud.bil", what="integer", n=8453, endian="little",
> signed=TRUE, size=2)
> BIL <- setValues(BIL, BIN)
> plot(BIL)
>
>
> With the img generated in ERDAS i can compare with the R result and clearly
> its not working good.
>
> Also, here you can have a copy of my files:
> http://ubuntuone.com/116tXWeA7rrwOc9SWsp6Wl (63kb)
>
> Anyone have a better recipe?
>
> Thanks in advance, regards!
>
>
> [1] http://www.nateko.lu.se/TIMESAT/timesat.asp
> [2] http://r.789695.n4.nabble.com/importing-bil-files-td1677546.html
>
> --
> Ing. Agr. Guillermo Federico OLMEDO
> Laboratorio de Geomática
> Área de Recursos Naturales
> EEA INTA Mendoza
>
> Oficina: San Martín 3853. Mayor. Drummond.
> Luján de Cuyo. Mendoza.
> ARGENTINA (M5507EVY)
> Tel: +54 (261) 496 3020 int. 252 / Cel. 261 6779074
> http://www.inta.gov.ar/mendoza/invest/Gr_RecursosNaturales.htm
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo



-- 
Michael Sumner
Institute for Marine and Antarctic Studies, University of Tasmania
Hobart, Australia
e-mail: mdsumner at gmail.com



More information about the R-sig-Geo mailing list