Book Image

Python Geospatial Development Essentials

By : Karim Bahgat
Book Image

Python Geospatial Development Essentials

By: Karim Bahgat

Overview of this book

Table of Contents (15 chapters)
Python Geospatial Development Essentials
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Installing third-party packages


In order to make our application, we will have to rely on the rich and varied ecosystem of third-party packages that already exists for GIS usage.

Note

The Python Package Index (PyPI) website currently lists more than 240 packages tagged Topic :: Scientific/Engineering :: GIS. For a less overwhelming overview of the more popular GIS-related Python libraries, check out the catalogue at the Python-GIS-Resources website created by the author:

http://pythongisresources.wordpress.com/

We will have to define which packages to use and install, and this depends on the type of application we are making. What we want to make in this book is a lightweight, highly portable, extendable, and general-purpose GIS application. For these reasons, we avoid heavy packages like GDAL, NumPy, Matplotlib, SciPy, and Mapnik (weighing in at about 30 MB each or about 150-200 MB if we combine them all together). Instead, we focus on lighter third-party packages specialized for each specific functionality.

Note

Dropping these heavy packages is a bold decision, as they contain a lot of functionality, and are reliable, efficient, and a dependency for many other packages. If you decide that you want to use them in an application where size is not an issue, you may want to begin now by installing the multipurpose NumPy and possibly SciPy, both of which have easy-to-use installers from their official websites. The other heavy packages will be briefly revisited in later chapters.

Specific installation instructions are given for each package in the chapter where they are relevant (see the following table for an overview) so that if you do not want certain functionalities, you can ignore those installations. Due to our focus to make a basic and lightweight application, we will only be installing a small number of packages. However, we will provide suggestions throughout the book about other relevant packages that you may wish to add later on.

Chapter

Installation

Purpose

1

Python

 

1

PIL

Raster data, management, and analysis

1

Shapely

Vector management and analysis

2

PyShp

Data

2

PyGeoj

Data

2

Rtree

Vector data speedup

4

PyAgg

Visualization

7

Py2exe

Application distribution

Note

The typical way to install Python packages is using pip (included with Python 2.7), which downloads and installs packages directly from the Python Package Index website. Pip is used in the following way:

  • Step 1—open your operating system's command line (not the Python IDLE). On Windows, this is done by searching your system for cmd.exe and running it.

  • Step 2—in the black screen window that pops up, one simply types pip install packagename. This will only work if pip is on your system's environment path. If this is not the case, a quick fix is to simply type the full path to the pip script C:\Python27\Scripts\pip instead of just pip.

For C or C++ based packages, it is becoming increasingly popular to make them available as precompiled wheel files ending in .whl, which has caused some confusion on how to install them. Luckily, we can use pip to install these wheel files as well, by simply downloading the wheel and pointing pip to its file path.

Since some of our dependencies have multiple purposes and are not unique to just one chapter, we will install these ones now. One of them is the Python Imaging Library (PIL), which we will use for the raster data model and for visualization. Let's go ahead and install PIL for Windows now:

  1. Go to https://pypi.python.org/pypi/Pillow/2.6.1.

  2. Click on the latest .exe file link for our 32-bit Python 2.7 environment to download the PIL installer, which is currently Pillow-2.6.1.win32-py2.7.exe.

  3. Run the installation file.

  4. Open the IDLE interactive shell and type import PIL to make sure it was installed correctly.

Another central package we will be using is Shapely, used for location testing and geometric manipulation. To install it on Windows, perform the following steps:

  1. Go to http://www.lfd.uci.edu/~gohlke/pythonlibs/#shapely.

  2. Download the Shapely wheel file that fits our system, looking something like Shapely‑1.5.7‑cp27‑none‑win32.whl.

  3. As described earlier, open a command line window and type C:\Python27\Scripts\pip install path\to\Shapely‑1.5.7‑cp27‑none‑win32.whl to unpack the precompiled binaries.

  4. To make sure it was installed correctly, open the IDLE interactive shell and type import shapely.