[GRASSLIST:1437] Re: import .bil DEM file (cascadia.bil)

Hi Daniel and the others,

I tried again to import that *.bil file, as some time has gone by since my initial attempts.
In general I have to admit that I am a newbee to GIS and my general approach to projections etc. is very much try and error ...

I am working in a Lat/Lon location, the cascadia.bil file reflects a UTM location - does that cause additional problems?
However, I tried to import it into both types of locations without success.
I get complaints about "bytes not match File size" regardless what I try ... (see below)

Thanks,

Torge

*** Lat/Lon location ***
GRASS:~/geodata/dem/cascadia > r.in.bin -s input=cascadia.bil output=cascadia.grass bytes=1 north=53 south=39 east=244 west=227
Using rows=14 cols=17
Bytes do not match File size
File Size 76589370 ... Total Bytes 238
Try bytes=321804 or adjusting input parameters

*** UTM location ***
GRASS:~/geodata/dem/cascadia > r.in.bin -s input=cascadia.bil output=cascadia.grass bytes=1 north=1710340.289 south=101590.289 east=749705.938 west=-738044.062
Using rows=1608749 cols=1487749
Bytes do not match File size
File Size 76589370 ... Total Bytes 1117932129
Try bytes=0 or adjusting input parameters

On Tue, 7 Oct 2003 17:04:21 -0700 (PDT), Daniel Victoria <daniel_victoria@yahoo.com> wrote:

You should be able to import the file using r.in.bin.
I don't have my linux box on now so I can't remember
the command but I think you must have the header file
with the same name as the bill file (just different
extension .bil and .hdr)

Also, you will have to play arounf with the bite
swaping option. Can't remember now if the motorola
(sun) needs bite swap on or off. Import and check the
values, if they are off than change the biteswap.
Acording to what you sent, the values - before
correcting for the offset - should range from 400 to
something in the order of 5000

Hope to have helped

Daniel

--- Torge Schuemann <ts@uvic.ca> wrote:

Hi,

for quite a while I am trying to import a *.bil file
into GRASS 5.0.1 by
using various modules (r.in.bin and r.in.gdal).
I am not familliar with the *.bil format, but the
archive "cascdem.tar.gz"
I downloaded from
http://geopubs.wr.usgs.gov/open-file/of99-369/
includes
some meta data which I applied when using the import
modules.

However, so far I haven't been lucky although I
think I more or less tried
every possible combination of the parameters given
below.

As info for the data set itself: It contains a
250-meter digital elevation
model (DEM) for Cascadia (latitude 39N - 53N,
longitude 116W - 133W), a
region that encompasses the Cascade volcanic arc,
the Cascadia subduction
zone, and the Juan de Fuca Ridge system offshore
Washington (USA) and
British Columbia (Canada).

Any help is appreciated, thank you all!

Cheers, Torge

Here below I copied the available information which
is included in the tar
archive.
***** cascadia.blw: *****
                  250.00000000000000
                    0.00000000000000
                 -250.00000000000000
              -737919.06250000000000
              1710215.28906250000000

***** cascadia.hdr: *****
BYTEORDER M
LAYOUT BIL
NROWS 6435
NCOLS 5951
NBANDS 1
NBITS 16
BANDROWBYTES 11902
TOTALROWBYTES 11902
BANDGAPBYTES 0

***** cascadia.prj *****
Projection LAMBERT
Zunits NO
Units METERS
Spheroid CLARKE1866
Xshift 0.0000000000
Yshift 0.0000000000
Parameters
  41 30 0.000 /* 1st standard parallel
  50 30 0.000 /* 2nd standard parallel
-124 30 0.000 /* central meridian
  38 0 0.000 /* latitude of projection's origin
0.00000 /* false easting (meters)
0.00000 /* false northing (meters)

***** cascadia.stx *****
1 5147 14378 9371.3 2076.8

***** excerpts from README.txt *****
This report contains a 250-meter digital elevation
model (DEM) for Cascadia
(latitude 39N - 53N, longitude 116W - 133W), a
region that encompasses the
Cascade volcanic arc, the Cascadia subduction zone,
and the Juan de Fuca
Ridge system. The DEM is distributed as file
cascdem.tar.gz (39 MB; 78MB
uncompressed).

The DEM contains elevation values in integer meters,
at regularly-spaced
points in a Lambert conformal conic projection with
standard parallels at
latitudes 41.5N and 50.5N, and a central longitude
of 124.5W (the
"Cascadia" projection.).

To ease data transfer for the widest possible range
of users, the DEM is
distributed as a BIL (Band Interleave by Line) file,
produced with the ARC
GRIDIMAGE command. For grids (the ARC term for a DEM
in the form of a
regular array of height values), such files are more
compact than ARC
export (.e00) files and USGS DEM-format files, and
are much faster to
create and import. They can also be read by many
applications other than
ARC. cascadia.bil is such a file of binary integers.
Elevations are stored
in cascadia.bil as unsigned positive 2-byte binary
integers, in Motorola
byte-order (default for Sun hardware), with an
offset of 10000. That is,
203 meters is stored as 10203 meters, and values
less than 10000 represent
negative elevations. Values of 0 in cascadia.bil
represent no data. Values
are given by row, west to east, starting at the
north edge of the region.

To convert CASCADIA files to an ARC grid

Assemble the cascadia.* files (.bil, .blw, .hdr,
prj; .stx is not
necessary) in one directory. Make this your
workspace.

      Arc: imagegrid cascadia casc1
      Arc: grid
      Grid: casc2 = con(casc1 <> 0, casc1 - 10000)
      Grid: &sys cp cascadia.prj casc2/prj.adf

If you DESCRIBE casc2 in ARC, you should get

      Description of Grid CASC2

      Cell Size = 250.000 Data Type: Integer
      Number of Rows = 6435 Number of Values = 8555
      Number of Columns = 5951 Attribute Data
(bytes) = 8

      BOUNDARY STATISTICS

      Xmin = -738044.062 Minimum Value =
-4853.000rs)
      0.00000

      Xmax = 749705.938 Maximum Value = 4378.000
      Ymin = 101590.289 Mean = -628.692
      Ymax = 1710340.289 Standard Deviation =
2076.818

                           COORDINATE SYSTEM
DESCRIPTION

      Projection LAMBERT
      Zunits UNKNOWN
      Units METERS
Spheroid
      CLARKE1866
      Parameters:
      1st standard parallel
         41 30
      0.000
      2nd standard parallel
         50 30
      0.000
      central meridian
        -124 30
      0.00
      latitude of projection's origin
         38 0
      0.000
      false easting (meters)
      0.00000
      false northing (meters)
      0.00000

__________________________________
Do you Yahoo!?
The New Yahoo! Shopping - with improved product search
http://shopping.yahoo.com

--
Dr. Torge Schuemann
School of Earth and Ocean Sciences (SEOS)
University of Victoria
Tel.: (250) 721-6177
Fax.: (250) 472-4620
Email: ts@uvic.ca
Web Page: http://biogeochemistry.uvic.ca
Mailing address (mail and courier):
P.O. Box 3050
E-Hut, Room 135c
School of Earth and Ocean Sciences, University of Victoria
Victoria, British Columbia, V8W 2Y2, Canada

I am working in a Lat/Lon location, the cascadia.bil file reflects a
UTM location - does that cause additional problems?

Looking at the metadata file:

Create a Lambert conformal conic location and import into that.
e.g.
"D" Other Projection
proj= lcc
ellipsoid= clark66
datum= nad27 ??
lat_0= 38N ??
lat_1= 41:30N
lat_2= 50:30N
lon_0= 124:30W
x_0= 0.0
y_0= 0.0

n=1710340.289
s=101590.289
w=-738044.062
e=749705.938
res=250.0

The setup screen doesn't have the room for all of the digits; you'll
have to tend to that after the mapsets are created. So after you make it
the grass prompt, do:

GRASS:~ > g.region n=1710340.289 s=101590.289 w=-738044.062 e=749705.938
GRASS:~ > g.region -p

and you should see res = 250 exactly.

*** UTM location ***

[LCC not UTM..]

GRASS:~/geodata/dem/cascadia > r.in.bin -s input=cascadia.bil
output=cascadia.grass bytes=1 north=1710340.289 south=101590.289
east=749705.938 west=-738044.062
Using rows=1608749 cols=1487749
Bytes do not match File size
File Size 76589370 ... Total Bytes 1117932129
Try bytes=0 or adjusting input parameters

try:
GRASS:~ > r.in.bin -s input=cascadia.bil output=cascadia.grass bytes=1 \
north=1710340.289 south=101590.289 east=749705.938 west=-738044.062 \
r=6435 c=5951 bytes=2

>> ***** cascadia.hdr: *****
>> BYTEORDER M

[-s or -b ?]

>> LAYOUT BIL
>> NROWS 6435
>> NCOLS 5951

[r= c= above]

>> NBANDS 1
>> NBITS 16

nbits 16 means you should use bytes=2 as well.

6435 rows * 5951 cols * 2bytes/cell = File Size 76589370

note from the man page:
The geographic coordinates north, south, east, and west describe the
outer edges of the geographic region. They run along the edges of the
cells at the edge of the geographic region and not through the center
of the cells at the edges.

So you may have to add/subtract 125.0m to each edge to get the correct
bounds. I believe ARC uses cell centers as the reference..

Are you *sure* r.in.gdal won't handle this as type "AIG"? That would
remove much of the pain from this process.

After that is in correctly & you can see it with d.rast & query good
numbers with d.what.rast, exit GRASS and then create your lat/lon
location. 'Import' the map from the LCC location with r.proj. Try GRASS
5.3+ if you want to reproject with a datum transform (say to WGS84).

good luck,
Hamish

>> for quite a while I am trying to import a *.bil file
>> into GRASS 5.0.1 by
>> using various modules (r.in.bin and r.in.gdal).
>> I am not familliar with the *.bil format, but the
>> archive "cascdem.tar.gz"
>> I downloaded from
>> http://geopubs.wr.usgs.gov/open-file/of99-369/
>> includes
>> some meta data which I applied when using the import
>> modules.
>>
>> However, so far I haven't been lucky although I
>> think I more or less tried
>> every possible combination of the parameters given
>> below.
>>
>> As info for the data set itself: It contains a
>> 250-meter digital elevation
>> model (DEM) for Cascadia (latitude 39N - 53N,
>> longitude 116W - 133W), a
>> region that encompasses the Cascade volcanic arc,
>> the Cascadia subduction
>> zone, and the Juan de Fuca Ridge system offshore
>> Washington (USA) and
>> British Columbia (Canada).
>>
>> Any help is appreciated, thank you all!
>>
>> Cheers, Torge
>>
>> Here below I copied the available information which
>> is included in the tar
>> archive.
>> ***** cascadia.blw: *****
>> 250.00000000000000
>> 0.00000000000000
>> 0.00000000000000
>> -250.00000000000000
>> -737919.06250000000000
>> 1710215.28906250000000
>>
>> ***** cascadia.hdr: *****
>> BYTEORDER M
>> LAYOUT BIL
>> NROWS 6435
>> NCOLS 5951
>> NBANDS 1
>> NBITS 16
>> BANDROWBYTES 11902
>> TOTALROWBYTES 11902
>> BANDGAPBYTES 0
>>
>> ***** cascadia.prj *****
>> Projection LAMBERT
>> Zunits NO
>> Units METERS
>> Spheroid CLARKE1866
>> Xshift 0.0000000000
>> Yshift 0.0000000000
>> Parameters
>> 41 30 0.000 /* 1st standard parallel
>> 50 30 0.000 /* 2nd standard parallel
>> -124 30 0.000 /* central meridian
>> 38 0 0.000 /* latitude of projection's origin
>> 0.00000 /* false easting (meters)
>> 0.00000 /* false northing (meters)
>>
>> ***** cascadia.stx *****
>> 1 5147 14378 9371.3 2076.8
>>
>> ***** excerpts from README.txt *****
>> This report contains a 250-meter digital elevation
>> model (DEM) for Cascadia
>> (latitude 39N - 53N, longitude 116W - 133W), a
>> region that encompasses the
>> Cascade volcanic arc, the Cascadia subduction zone,
>> and the Juan de Fuca
>> Ridge system. The DEM is distributed as file
>> cascdem.tar.gz (39 MB; 78MB
>> uncompressed).
>>
>> The DEM contains elevation values in integer meters,
>> at regularly-spaced
>> points in a Lambert conformal conic projection with
>> standard parallels at
>> latitudes 41.5N and 50.5N, and a central longitude
>> of 124.5W (the
>> "Cascadia" projection.).
>>
>> To ease data transfer for the widest possible range
>> of users, the DEM is
>> distributed as a BIL (Band Interleave by Line) file,
>> produced with the ARC
>> GRIDIMAGE command. For grids (the ARC term for a DEM
>> in the form of a
>> regular array of height values), such files are more
>> compact than ARC
>> export (.e00) files and USGS DEM-format files, and
>> are much faster to
>> create and import. They can also be read by many
>> applications other than
>> ARC. cascadia.bil is such a file of binary integers.
>> Elevations are stored
>> in cascadia.bil as unsigned positive 2-byte binary
>> integers, in Motorola
>> byte-order (default for Sun hardware), with an
>> offset of 10000. That is,
>> 203 meters is stored as 10203 meters, and values
>> less than 10000 represent
>> negative elevations. Values of 0 in cascadia.bil
>> represent no data. Values
>> are given by row, west to east, starting at the
>> north edge of the region.
>>
>> To convert CASCADIA files to an ARC grid
>>
>> Assemble the cascadia.* files (.bil, .blw, .hdr,
>> prj; .stx is not
>> necessary) in one directory. Make this your
>> workspace.
>>
>> Arc: imagegrid cascadia casc1
>> Arc: grid
>> Grid: casc2 = con(casc1 <> 0, casc1 - 10000)
>> Grid: &sys cp cascadia.prj casc2/prj.adf
>>
>> If you DESCRIBE casc2 in ARC, you should get
>>
>> Description of Grid CASC2
>>
>> Cell Size = 250.000 Data Type: Integer
>> Number of Rows = 6435 Number of Values = 8555
>> Number of Columns = 5951 Attribute Data
>> (bytes) = 8
>>
>> BOUNDARY STATISTICS
>>
>> Xmin = -738044.062 Minimum Value =
>> -4853.000rs)
>> 0.00000
>>
>> Xmax = 749705.938 Maximum Value = 4378.000
>> Ymin = 101590.289 Mean = -628.692
>> Ymax = 1710340.289 Standard Deviation =
>> 2076.818
>>
>> COORDINATE SYSTEM
>> DESCRIPTION
>>
>> Projection LAMBERT
>> Zunits UNKNOWN
>> Units METERS
>> Spheroid
>> CLARKE1866
>> Parameters:
>> 1st standard parallel
>> 41 30
>> 0.000
>> 2nd standard parallel
>> 50 30
>> 0.000
>> central meridian
>> -124 30
>> 0.00
>> latitude of projection's origin
>> 38 0
>> 0.000
>> false easting (meters)
>> 0.00000
>> false northing (meters)
>> 0.00000

.

I tried again to import that *.bil file, as some time has gone by
since my initial attempts.

a little more ideas..

From: http://geopubs.wr.usgs.gov/open-file/of99-369/

"Elevations are stored in cascadia.bil as unsigned positive 2-byte
binary integers, in Motorola byte-order (default for Sun hardware), with
an offset of 10000. That is, 203 meters is stored as 10203 meters, and
values less than 10000 represent negative elevations. Values of 0 in
cascadia.bil represent no data. Values are given by row, west to east,
starting at the north edge of the region."

so try without the -s signed-bit flag, with the -b byteswap flag[*],
and with anull=0.

[*] SUN is big endian, I assume you are importing to little endian (PC)?

so that makes it:

GRASS:~ > r.in.bin -b input=cascadia.bil output=cascadia.grass bytes=1 \
north=1710340.289 south=101590.289 east=749705.938 west=-738044.062 \
r=6435 c=5951 bytes=2 anull=0

but still check the +/- 125.0, you may need to adjust the edges.

finally recorrect the z-values with:

GRASS:~ > g.region rast=cascadia.grass
GRASS:~ > r.mapcalc "cascadia.grass = cascadia.grass - 10000"

hope it works,
Hamish

Hi Hamish,

thanks a lot for your help. It worked out exactly as you suggested!

Torge

On Wed, 8 Oct 2003 21:47:57 +1300, Hamish <hamish_nospam@yahoo.com> wrote:

.. make that

GRASS:~ > r.in.bin -b input=cascadia.bil output=cascadia.grass \
north=1710340.289 south=101590.289 east=749705.938 west=-738044.062 \
r=6435 c=5951 bytes=2 anull=0

[+/- 125.0?]

hope it works,
Hamish

--
Dr. Torge Schuemann
School of Earth and Ocean Sciences (SEOS)
University of Victoria
Tel.: (250) 721-6177
Fax.: (250) 472-4620
Email: ts@uvic.ca
Web Page: http://biogeochemistry.uvic.ca
Mailing address (mail and courier):
P.O. Box 3050
E-Hut, Room 135c
School of Earth and Ocean Sciences, University of Victoria
Victoria, British Columbia, V8W 2Y2, Canada