Sign In Start Free Trial
Account

Add to playlist

Create a Playlist

Modal Close icon
You need to login to use this feature.
  • Book Overview & Buying Python Geospatial Analysis Cookbook
  • Table Of Contents Toc
  • Feedback & Rating feedback
Python Geospatial Analysis Cookbook

Python Geospatial Analysis Cookbook

By : Diener
4.4 (5)
close
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
close
12
A. Other Geospatial Python Libraries
13
B. Mapping Icon Libraries
14
Index

Installing SciPy, PySAL, and IPython

SciPy is a collection of Python libraries, including SciPy library, matplotlib, pandas, SymPy, and IPython. The SciPy library itself is used for many operations, but we are particularly interested in the spatial module. This module can do many things including running a nearest neighbor query.

PySAL is a geospatial computing library that's used for spatial analysis. Creating models and running simulations directly from Python code are some of the many library functions that PySAL offers. PySAL is a library that, when put together with our visualization tools such as matplotlib, gives us a great tool.

IPython is a Python interpreter for a console that replaces the normal Python console you may be used to when running and testing Python code from your terminal. This is really just an advanced interpreter with some cool features, such as Tab completion, which means that beginners can get commands quickly by typing a letter and hitting Tab. The IPython notebooks help share code in the form of a web page, including code, images, and more without any installation.

Getting ready

The dependency jungle we looked at earlier is back and we need three more universal installations to our Ubuntu system using apt-get install as follows:

$ sudo apt-get install libblas-dev liblapack-dev gfortran

Note

Windows and Mac users can use a full installer (http://www.scipy.org/install.html), such as Anaconda or Enthought Canopy, which will perform all the installation dependencies for you in one go.

Three dependencies are used for the SciPy installation. PySAL depends on SciPy so make sure to install SciPy first. Only IPython does not need any extra installations.

Start up your Python virtual environment with the following code:

mdiener@mdiener-VirtualBox:~$ workon pygeoan_cb
(pygeoan_cb)mdiener@mdiener-VirtualBox:~$

How to do it...

Let's look at these steps:

  1. First, we'll install SciPy since PySAL depends on it. This will take a while to install; it took my machine 5 minutes to go through so take a break:
    $ pip install scipy
    
  2. PySAL can be installed super quickly using pip:
    $ pip install pysal
    
  3. As usual, we'd like to see whether everything's working, so let's fire up the Python shell as follows:
    (pygeoan_cb)mdiener@mdiener-VirtualBox:~$python
    >>> import scipy
    >>> import pysal
    >>>
    
  4. IPython is to be installed globally or inside the virtual environment using pip as follows:
    $ pip install ipython
    

How it works...

SciPy and PySAL libraries are both geared to help accomplish various spatial analysis duties. The choice of tool is based on the task at hand, so make sure that you check which library offers what function at the command prompt as follows:

>>> from scipy import spatial
>>> help(spatial)

The output should look like what is shown in the following screenshot:

How it works...

Create a Note

Modal Close icon
You need to login to use this feature.
notes
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

Delete Note

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

Edit Note

Modal Close icon
Write a note (max 255 characters)
Cancel
Update Note

Confirmation

Modal Close icon
claim successful

Buy this book with your credits?

Modal Close icon
Are you sure you want to buy this book with one of your credits?
Close
YES, BUY