Geoscience Reference
In-Depth Information
GDAL implements a specific driver for the different file formats supported.
The corresponding GDAL class is GDALDriver . It manages all information
about the format, e.g. metadata are format specific and are accessed via the class
GDALDriver . A new dataset with its associated raster bands is always created via
the corresponding driver. This can be performed with either one of the two methods
Create and CreateCopy , as visualized in Fig. 14.8 . More details on the creation
of new datasets via the API are given in Sect. 14.3.4 .
There are two special instances of GDALRasterBand : overviews and
maskbands. Unlike normal raster bands, they are not created via the GDALDriver
class. Instead, they are derived directly from a dataset or another raster band. The
respective methods are BuildOverviews and CreateMaskBand , as is illus-
trated by the solid connectors in Fig. 14.8 . Overviews can represent a raster band in
different resolutions. They are covered in Chap. 7 . A maskband identifies pixels that
are not valid data. The concept is very similar to no-data values. In case of a byte
type image where all 256 pixel values are in use, creating a separate maskband can
be a valuable alternative.
Reading and writing the actual raster data is performed via member functions
of the class GDALRasterBand (see lower right solid arrow in Fig. 14.8 ). Filling
( Fill() ) is used to initialize a raster with a constant value. RasterIO is most
flexible for reading and writing data of variable length (e.g. pixels or entire lines).
For optimal efficiency, entire blocks can be read and written via ReadBlock() and
WriteBlock() . The size of these blocks can be retrieved via the member func-
tion GetBlockSize() of class GDALRasterBand . In the following sections,
reading and writing raster files will be discussed in more detail.
14.3.3 Read Raster Files
To illustrate how to read a multi-band raster file representing a Landsat scene, we
write a small program.We create an instance of the GDAL class GDALDataset , and
call the appropriate function to open the corresponding raster file file ( GDALOpen ).
Attributes of the object such as the number of bands ( nBands ), columns ( nRaster -
XSize ) and rows ( nRasterYSize ) are automatically set after opening the dataset.
These attributes are protected, which means that you cannot access them directly.
Hiding internal representation is typical for object based programming and is
referred to as encapsulation . For instance, instead of accessing the class attribute
nRasterXSize directly, you use the class method GetRasterXSize() .Like-
wise, you set the class attributes via the class member functions. For instance, to
set the projection of an image, you use SetProjection() . A PROJ4 projection
string must then be provided as an argument of the function.
As introduced in Sect. 14.1 , GDALmakes use of drivers to support different raster
formats. To notify your programwhich drivers are supported, you start by registering
all drivers with a call to GDALAllRegister() .
 
Search WWH ::




Custom Search