-
Book Overview & Buying
-
Table Of Contents
Python GeoSpatial Analysis Essentials
By :
To start analyzing geospatial data using Python, we are going to make use of two freely available third-party libraries:
Let's go ahead and get these two libraries installed into your Python setup so we can start using them right away.
GDAL, or more accurately the GDAL/OGR library, is a project by the Open Source Geospatial Foundation to provide libraries to read and write geospatial data in a variety of formats. Historically, the name GDAL referred to the library to read and write raster-format data, while OGR referred to the library to access vector-format data. The two libraries have now merged, though the names are still used in the class and function names, so it is important to understand the difference between the two.
A default installation of GDAL/OGR allows you to read raster geospatial data in 100 different formats, and write raster data in 71 different formats. For vector data, GDAL/OGR allows you read data in 42 different formats, and write in 39 different formats. This makes GDAL/OGR an extremely useful tool to access and work with geospatial data.
GDAL/OGR is a C++ library with various bindings to allow you to access it from other languages. After installing it on your computer, you typically use the Python bindings to access the library using your Python interpreter. The following diagram illustrates how these various pieces all fit together:

Let's go ahead and install the GDAL/OGR library now. The main website of GDAL (and OGR) can be found at http://gdal.org.
How you install it depends on which operating system your computer is using:
Alternatively, you can install GDAL/OGR and Shapely using the OSGeo installer, which can be found at http://trac.osgeo.org/osgeo4w.
Once you have installed it, you can check that it's working by firing up your Python interpreter and typing import osgeo.gdal and then import osgeo.ogr. If the Python command prompt reappears each time without an error message, then GDAL and OGR were successfully installed and you're all ready to go:
>>>import osgeo.gdal >>>import osgeo.ogr >>>
Shapely is a geometry manipulation and analysis library. It is based on the Geometry Engine, Open Source (GEOS) library, which implements a wide range of geospatial data manipulations in C++. Shapely provides a Pythonic interface to GEOS, making it easy to use these manipulations directly within your Python programs. The following illustration shows the relationship between your Python code, the Python interpreter, Shapely, and the GEOS library:

The main website for Shapely can be found at http://pypi.python.org/pypi/Shapely.
The website has everything you need, including complete documentation on how to use the library. Note that to install Shapely, you need to download both the Shapely Python package and the underlying GEOS library. The website for the GEOS library can be found at http://trac.osgeo.org/geos.
How you go about installing Shapely depends on which operating system your computer is using:
Note that if you install the GDAL Complete package from the preceding website, you will already have GEOS installed on your computer.
Once GEOS has been installed, you can install Shapely using pip, the Python package manager:
pip install shapely
If you don't have pip installed on your computer, you can install it by following the instructions at https://pip.pypa.io/en/latest/installing.html.
pip install shapely to install the Shapely library itself.Once you have installed it, you can check that the Shapely library is working by running the Python command prompt and typing the following command:
>>> import shapely.geos >>>
If you get the Python command prompt again without any errors, as in the preceding example, then Shapely has been installed successfully and you're all set to go.
Change the font size
Change margin width
Change background colour