Geoscience Reference
In-Depth Information
allows the re-use of functionality, without the need to re-develop it each time a new
application is developed. As an application programmer, you can be relieved from the
intricate details of how each different data format needs to be accessed by a generic
interface (API); which is managed by means of drivers . These drivers are based in
turn on the individual libraries that are developed for each data format (e.g. libgeotiff,
libsqlite, etc.). As can be seen in Fig. 14.1 , different APIs exist for raster (GDAL)
and vector (OGR) data. Their unification is under discussion and it is foreseen within
GDAL2.0 1 (see also Sect. 19.1.1 ) .
GDAL provides an additional layer between the API and its utilities in the form
of a series of Simplified Wrapper and Interface Generator (SWIG) bindings. These
SWIG bindings allow the integration of GDAL functionality written in C/C++ into
other programming languages, such as Python, Java, Ruby, Perl, C#, Lua, VB6, R,
PHP and TCL.
14.2 OGR API
Python was developed by Guido van Rossum and first appeared in 1991 as an open
source, object-oriented programming language but that was also capable of func-
tional, procedural programming required for scripting. It is considered to be highly
versatile, easily readable and relatively intuitive to learn. To fully benefit from this
section of the topic, some experience in programming in Python would be beneficial.
For those unfamiliar with Python, we recommend reading an introductory primer to
Python 2 or the widely cited Python book, Dive into Python. 3
Unlike compiled programming languages, like C and C++, it is possbile to run
Python interactively from the command line. Once Python is installed, it suffices
to type python at the command prompt to open the Python CLI and start to enter
Python commands. This is very useful if you are learning Python as it allows you to
test individual parts of the program in a step by step approach. IPython 4 is an inter-
active Python shell that provides the user with additional functionality compared to
the standard Python CLI, which includes auto-completion, history and many other
features.
Over the last decade there has been a surge in the number of Python packages
available. Some provide generic utilities, whilst others provide a specialist set of
functions relevant to a discipline or type of data. Python packages such as Numpy,
SciPy and Matplotlib are widely used for processing and manipulating geospatial
data. In addition to the GDAL/OGR Python bindings, packages such as Fiona 5 and
Shapely 6 provide extensive capabilities for handling vector spatial data. For the
1 http://trac.osgeo.org/gdal/wiki/GDAL20Changes
2 http://docs.python.org/tut/tut.html
3 http://diveintopython.net
4 http://ipython.org
5 http://toblerity.org/fiona/fiona.html
6 https://github.com/sgillies/shapely
 
Search WWH ::




Custom Search