On Mon, Mar 22, 2010 at 12:09 PM, Sebastian Leuzinger <sebastian.leuzin...@env.ethz.ch> wrote: > Dear list > > Has anyone got a recipie at hand to import .bil files into R? From what I > understand the .bil files I got contain layered matricies which I would lke > to make available in R as an array or list. > > GIS people seem to be familiar with the .bil format but I am not using any > GIS software and would prefer to deal with the data in R. > > I use the latest version of R on Mac OSX 10.5.8.
There's another complication that might make things more complicated, or, pervesely, make it simpler... .bil files should come with a .hdr file. The .bil is just the NxMxZ raw data. No definition of the structure or coordinates at all - it could be NxMxZ or ZxNxM or even any numbers with the right product. All that info is held in the accompanying .hdr file. If you cant get the .hdr file and don't know the structure and it isn't a product of three primes times 4, 8, or 16, then you are possibly in trouble... So without a .hdr and with dimension known you can try using R's binary connection functions to read in the raw bytes and whack up an array of the right dimension. See ?readBin. Or you can create a .hdr file yourself. They are plain text and quite descriptive - here's one I made earlier: BYTEORDER I LAYOUT BIL NROWS 22 NCOLS 20 NBANDS 1 NBITS 32 BANDROWBYTES 80 TOTALROWBYTES 80 PIXELTYPE FLOAT ULXMAP 22.7946212255725 ULYMAP 5.45149245118748 XDIM 0.333594138544999 YDIM 0.333594138544999 this is for a single layer 22x20 grid of floating point numbers. You can use writeGDAL with the EHdr driver to create these things (and the .bil files) to see what it should be, or read a spec somewhere... How's that? Barry ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.