Geoscience Reference
In-Depth Information
to the source. This is important if the output format is different than the input for-
mat. With the fourth argument, creation options can be set. For instance, metadata,
compression, band encoding, etc. can be set here. Some examples are provided in
Sects.
14.3.4
and
14.3.7
. The last two arguments are used to report progress and are
not used here (
NULL
). An example on how to use progress is provided in our snippet
in Sect.
14.3.7
.
14.3.6.3 CreateCopy Mode with Virtual Dataset
The final and most flexible version of our utility makes use of the virtual dataset.
This is a powerful method and it is recommended in case a maximum variety of
image formats must be supported. Notice that for this particular utility, we are still
limited by the drivers that support color tables. This new version supports an option
for the format of the output dataset. We therefore adapt the usage in the code block
on argument parsing and add an extra
if
statement:
stlosError <<"usage: "<< argv[0] <<" -ct <ascii_Filename>
→
<inputFilename> [[-of <format>] <outputFilename>]";
//loop over all command line options
for
(
int
i=1;i<argc;i++){
...
else if
(stlsOption=="-of"||stlsOption=="--oformat")
stlsFormat=argv[++i];
...
}
The remainder of the code is similar to the previous version of the utility. We con-
centrate on the code block corresponding to the
else
statement (output is provided:
destination image is not empty). Instead of creating immediately a new dataset as
in the previous version, we first create a virtual copy of the input. The reason for
creating a virtual dataset is that we can change its attributes after it has been cre-
ated. Some drivers (e.g. PNG) do not support opening datasets in the
GA_Update
mode. Consequently, we cannot alter the dataset and hence not the color table once
it has been created. The trick therefore is to first create a virtual dataset with the
CreateCopy
method and then change its attributes, e.g. by adding a color table.
Once this is done, we call the
CreateCopy
to create the output dataset in the final
format. It is possible to have the intermediate virtual dataset reside in memory only,
i.e. without having it being writing to file. This can be achieved by providing an
empty filename as the first argument of
CreateCopy
. The following code replaces
the
else
code block of the previous version.
else
{//create new data set with CreateCopy
//open input dataset in read only mode
GDALDataset *poSrcDataset;
poSrcDataset = (GDALDataset *)
→
GDALOpenShared(stlsSrcImageFilename.c_str(), GA_ReadOnly);
Search WWH ::
Custom Search