Geoscience Reference
In-Depth Information
14.3 GDAL API
14.3.1 GDAL API Using C++
The core of the GDAL/OGR code is written in C/C++. Although C and C++ are
different programming languages, you will often see them combined. Originally
developed by Dennis Ritchie, the C language is the older of the two. From all high
level programming languages in use, it is probably the one that is closest to the
machine hardware. Most of the Unix and Linux operating systems are written in
C. 12 As the saying goes, “C provides all the rope you need to hang yourself”, it is at
the same time a very powerful and very error prone programming language. In 1979,
Bjarne Stroustrup, extended the C language by introducing the concept of classes,
thereby giving the C++ language its object oriented character. Other than procedural
programming, it is organized around objects, being instances of classes that contain
member functions (methods) and attributes (variables). For those of you unfamiliar
with object oriented programming, the illustration in Sect. 14.3.2 can clarify this
concept.
C++ is backwards compatible to C, which allows you to mix the two languages.
A huge advantage is that existing code can be re-used. The disadvantage is the risk
of being trapped in procedural programming, where some of the power of the object
oriented paradigm is lost. GDAL provides a distinct API for C and C++, though you
will find a mixture of C and C++ code in the C++ API. Explaining the fundamentals
of C and C++ is beyond the scope of this topic. Most famous are the reference topics
written by their designers: “The C Programming Language” by Brian Kernighan and
Dennis Ritchie and “The C++ Programming Language” by Bjarne Stroustrup.
We start this section with some fundamental concepts of the GDAL API using
C++: reading and writing raster datasets. We recommend to also read the fine tutorial
available on the Internet, 13 which not only deals with the same concepts using C++,
but also using C and Python. Those of you more familiar with C and Python can use
it to find the corresponding instructions for the ones illustrated in C++ here.
When writing programs in C and C++ using an external library such as GDAL, the
library and the associated include files must be located on your computer. Standard
install scripts on a Linux system use /usr/lib and /usr/include/gdal or
/usr/local/lib and /usr/local/include/gdal . 14 , 15 Either way, your
compiler and linker should be able to find them. One of the fundamental GDAL
source files to include is gdal_priv.h .
12 Some parts written in a low level assembly language.
13 http://www.gdal.org/gdal_tutorial.html
14 GDAL also depends on other libraries such as GEOS, PROJ4 and TIFF.
15 For building on Windows, consult http://trac.osgeo.org/gdal/wiki/BuildingOnWindows .
 
Search WWH ::




Custom Search