Geoscience Reference
In-Depth Information
one of the possible values in the input image. In our example, the values are integers
of type GDT_Byte and range from 0 to 255. The remaining four columns represent
the intensities for the colors red, green, blue and the transparency alpha. A typical
color table for a binary map can look like this:
0 255 255 255 255
1 100 100 100 255
We assign white to the value 0 and gray to the value 1. The alpha components are
set to 255 (fully opaque) for both values. The utility adds the color table to an existing
raster dataset. We will create three versions of the utility. Each version illustrates a
different method of opening a dataset. The complexity increases slightly with each
version, but also adds more flexibility to the utility.
In a first version, we open the input dataset in update mode and add the color table.
Not all file formats support a color table. The format of the input dataset should be
a format that supports it.
In a second version, we support the creation of a new (GeoTIFF) output dataset.
The TIFF format does not support storing the alpha component, so it is ignored. 20
Finally, the third version illustrates the use of the virtual driver. This is the most
flexible version of the utility, because it supports the creation of specific file formats,
such as PNG for instance.
14.3.6.1 Update Mode
The first version of our utility to add a color table to a dataset is to update an existing
dataset. The color table is read from an ASCII text file that is defined with the option
-ct . To remove a color table from a dataset, you can use the option -ct with the
argument “none”. The utility also supports a help function with the options -h and
—-help .
The current snippet implements a simplified version of command line parsing. A
full-fledged implementation would test all options against wrong input and support
options in both short ( -o ) and long ( —-option ) format, with or without the equal
sign ( —-option=argument ).
The current snippets throws an exception in the following cases:
help info was requested using the options -h or -help ;
unknown option (e.g. -foo);
more than a single filename was provided on the command line.
The utility detects a filename when it encounters a command line argument that
does not start with a dash ( - ) and is not a value linked to an option ( —-option
value ). The exception is caught and an error message is shown on the console.
20 http://partners.adobe.com/public/developer/en/tiff/TIFF6.pdf
 
 
Search WWH ::




Custom Search