Geoscience Reference
In-Depth Information
In the following snippet we write an entire image line per line. Filling in the line
buffer with useful information is specific to the application and is not part of the snip-
pet. This code replaces the line perform data set (write) operations
here ...
in the previous snippet. Notice that we already closed the dataset there.
Closing the file is important and particularly in a write operation as it actually flushes
the data to file. Forgetting to close a file cannot only result in an empty output file
but also in locked files that cannot be accessed at a later stage.
GDALRasterBand *poBand;
unsigned short pnbuffer[512];
//fetch first raster band
poBand = poDataset->GetRasterBand(1);//GDAL uses 1 based index
//process image line per line
for ( int irow=0;irow<poBand->GetYSize();++irow){
//fill in the line buffer with useful information here...
//write buffer to raster band
poBand->RasterIO(GF_Write, 0, irow, 512, 1, pnbuffer, 512,
1, GDT_UInt16, 0, 0);
}
14.3.5 Parse Options from the Command Line
Parsing options from the command line is a task that has to be performed repetitively
and that can be tedious. The GDAL API implements some functions to facilitate this
task. For instance, the function GDALGeneralCmdLineProcessor automates
the parsing of the general options in the GDAL utilities (see Chap. 4 ) . You also can
make use of some of the macro functions that have been defined in GDAL for your
own utilities. For instance, to check whether a specific command line was requested
by the user, you can use the macro EQUAL defined by GDAL.
As an example, the code gdalinfo.c that implements the gdalinfo utility,
provides a switch -mm to compute the minimum and maximum values in a raster. It
is parsed using the macro EQUAL
#define EQUAL(x,y) (strcasecmp(a,b)==0)
int main( int argc, char ** argv )
int bComputMinMax=FALSE;
for ( i = 1; i < argc; i++ ){
if ( EQUAL(argv[i],"-mm") )
bComputeMinMax = TRUE;
//check for other options
}
...
}
 
 
Search WWH ::




Custom Search