Sign In Start Free Trial
Account

Add to playlist

Create a Playlist

Modal Close icon
You need to login to use this feature.
  • Python Geospatial Analysis Cookbook
  • Toc
  • feedback
Python Geospatial Analysis Cookbook

Python Geospatial Analysis Cookbook

By : Diener
4.4 (5)
close
Python Geospatial Analysis Cookbook

Python Geospatial Analysis Cookbook

4.4 (5)
By: Diener

Overview of this book

Geospatial development links your data to places on the Earth’s surface. Its analysis is used in almost every industry to answer location type questions. Combined with the power of the Python programming language, which is becoming the de facto spatial scripting choice for developers and analysts worldwide, this technology will help you to solve real-world spatial problems. This book begins by tackling the installation of the necessary software dependencies and libraries needed to perform spatial analysis with Python. From there, the next logical step is to prepare our data for analysis; we will do this by building up our tool box to deal with data preparation, transformations, and projections. Now that our data is ready for analysis, we will tackle the most common analysis methods for vector and raster data. To check or validate our results, we will explore how to use topology checks to ensure top-quality results. This is followed with network routing analysis focused on constructing indoor routes within buildings, over different levels. Finally, we put several recipes together in a GeoDjango web application that demonstrates a working indoor routing spatial analysis application. The round trip will provide you all the pieces you need to accomplish your own spatial analysis application to suit your requirements.
Table of Contents (15 chapters)
close
12
A. Other Geospatial Python Libraries
13
B. Mapping Icon Libraries
14
Index

Installing pyproj and NumPy

The pyproj is a wrapper around the PROJ.4 library that works with projections and performs transformations (https://pypi.python.org/pypi/pyproj/) in Python. All your geographic information should be projected into one of the many coordinate systems supported by the European Petroleum Survey Group (EPSG). This information is necessary for the systems to correctly place data at the appropriate location on Earth. The geographic data can then be placed on top of each other as layers upon layers of data in order to create maps or perform analysis. The data must be correctly positioned or we won't be able to add, combine, or compare it to other data sources spatially.

Data comes from many sources and, often, a projection is not the same as a dataset. Even worse, the data could be delivered with a description from a data provider stating it's in projection UTM31 when, in reality, the data is in projection UTM34! This can lead to big problems later on when trying to get your data to work together as programs will throw you some ugly error messages.

NumPy is the scientific backbone of number crunching arrays and complex numbers that are used to power several popular geospatial libraries including GDAL (geospatial abstraction library). The power of NumPy lies is in its support for large matrices, arrays, and math functions. The installation of NumPy is, therefore, necessary for the other libraries to function smoothly, but is seldom used directly in our quest for spatial analysis.

Getting ready

Fire up your virtual environment, if it is not already running, using the following standard start command:

$ workon pygeoan_cb

Your prompt should now look like this:

(pygeoan_cb)mdiener@mdiener-VirtualBox:~$

Note

If workon for some reason does not start your virtual environment, you can start it simply by executing source /home/mdiener/venvs/pygeoan_cb/bin/activate from the command line; try the steps listed in the Installing virtualenv and virtualenvwrapper recipe again to get it going.

Now, we need to install some Python tools for development that allow us to install NumPy, so run this command:

$ sudo apt-get install -y python-dev

You are now ready to move on and install pyproj and NumPy inside your running virtual environment.

How to do it...

Simply fire up virtualenv and we will use the pip installer to do all the heavy lifting as follows:

  1. Use pip to go ahead and install NumPy; this can take a couple of minutes as many lines of installation verbosity are written on screen:
    $ pip install numpy
    

    Windows users can grab the .whl file for NumPy and execute it using following command:

    pip install numpy -1.9.2+mkl-cp27-none-win32.whl
    
  2. Use pip one more time to install pyproj:
    $ pip install pyproj
    

    Windows users can use the following command to install pyproj:

    pip install pyproj-1.9.4-cp27-none-win_amd64.whl
    
  3. Wait a few minutes; NumPy should be now running along with pyproj. To test if it's worked out, enter the following command in the Python console. The output should look like this:
    (pygeoan_cb)mdiener@mdiener-VirtualBox:~/venv$ python
    Python 2.7.3 (default,  Feb 27 2014, 19:58:35)
    [GCC 4.6.3] on linux2
    Type “help”,  “copyright”, “credits”, or  “license” for more information.
    >> import numpy
    >> import pyproj
    

No errors, I hope. You have now successfully installed NumPy and pyproj.

Note

All sorts of errors could show up, so please take a look at the respective installation links to help you solve them:

For pyproj: https://pypi.python.org/pypi/pyproj/

For NumPy: http://www.numpy.org

How it works...

This easy installation works using the standard pip installation method. No tricks or special commands are needed. You need to simply execute the pip install <library_name> command and you are off to the races.

Tip

Library names can be found by visiting the https://pypi.python.org/pypi web page if you are unsure of the exact name you want to install.

bookmark search playlist font-size

Change the font size

margin-width

Change margin width

day-mode

Change background colour

Close icon Search
Country selected

Close icon Your notes and bookmarks

Delete Bookmark

Modal Close icon
Are you sure you want to delete it?
Cancel
Yes, Delete