Tutorial 1

1. Converting ASCII elevation data to IPW format.

Before getting started, you need to get the ASCII elevation data. To download the data, you can either download it directly:

Send me the file!

Or, you can retrieve it using anonymous ftp:

ftp snobear.colorado.edu
Name: anonymous
Password:Type your email address
ftp> cd pub
ftp> get elevs.asc
ftp> bye

To begin, we need to convert the ASCII data to binary representation. We'll use the command atob for this. The usage for atob is as follows:

atob -{1,2,4} [file] > newfile

The -{1,2,4} is a UNIX switch indicating the number of bytes of the output file. There are 8 bits in a byte; we want to convert to 12-bit data, which will require 2 bytes (16 bits). So, to make the ASCII to binary conversion of the file elevs.asc, type

atob -2 elevs.asc > elevs.bin

You should look at the binary data to see how it is different from the ASCII version by using the UNIX more command:

more newfile

Use Control-C (^C) to get out of viewing the file, or press the Space Bar to scroll through.

Now, you need to add an IPW basic image header to the binary data so that IPW commands will recognize the data as an IPW file using the IPW command mkbih. The usage for mkbih is:

mkbih -- make an IPW basic image header

Usage: mkbih -l #lines -s #samps [-a string,...] [-b #bands] [-y #bytes,...] [-i #bits,...] [-f] [image] > [newimage]


l: # lines / image
s: # samples / line
a: annotation string(s)
b: # bands (pixels) / sample (default: 1)
y: # bytes / pixel (default: 1, or large enough for nbits)
i: # bits / pixel (default: nbytes * 8)
f: force header output; ignore any input

image: input image file
newimage: output image file

For the Niwot DEM, we only have one band, we need two bytes to store the 12-bit data, we don't need an annotation string, and we don't want to force the header output. So, we can type:

mkbih -l 175 -s 423 -i 12 elevs.bin > elevs.ipw

Check out the new header on the file:

more elevs.ipw
Use ^C to escape viewing the whole binary part of the file.

Now we have the DEM in IPW format, but there's more that we can do to put the file in its spatial context. We'll add a geodetic header using IPW's mkgeoh command. The usage is:

mkgeoh -- add a geodetic header to an image

Usage: mkgeoh -o coord,coord -d incr,incr -u units -c csys [-b band,...] [-f] [image] > [newimage]


o: u,v coordinates of image origin
d: u,v increment per line,sample
u: u,v units of measure
c: u,v coordinate system identifier
b: band #s to receive header (default: all)
f: force header output; ignore any input image


image: input image file
newimage: output image file

To add the geodetic header for the Niwot DEM, type:

mkgeoh -c UTM -u meters -o 4434990,444190 -d -20,20 elevs.ipw > g_elevs.ipw

Now check the file to see what this command added to your file:

more g_elevs.ipw

Are we done yet? No! Of course not. We have an elevation range of 978 m, but we have 4096 values that we can store it in. We'd like to map the 12-bit values into the range of our elevations. This is a fundamental property of IPW: quantization.

IPW image pixel values are represented externally as unsigned integers. This is the most portable possible binary representation. It is also the traditional pixel representation for digital image data. However, most real-world phenomenon are more conveniently represented as floating-point, rather than integer quantities. IPW solves this problem by storing, in an optional image header, the parameters governing the quantization of pixel values from floating-point to integer. By adding this header, IPW components that require floating-point values will be able to automatically transform the integer data to floating point, and automatically transform the output from floating-point to integer. We can add the header using the IPW command mklqh. The usage is:

mklqh -- construct a linear quantization (LQ) header

Usage: mklqh -m val,val,... [-u units] [-i interp] [-b band,...] [-f] [image] > [newimage]


m: pixel,fpixel breakpoint pairs
u: fpixel units of measure
i: interpolation function (default: "linear")
b: band #s to receive map (default: all)
f: force header output; ignore any input image


image: input image file
newimage: output image file

So, we'll add the LQ header to our DEM by typing:

mklqh -m 0,3107,4095,4085 g_elevs.ipw > DEM.ipw

Now we're ready to go!

If you want to return to the Overview Page, Click Here!

If you want to go on to the next tutorial, Click Here!