Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases now! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Python Geospatial Analysis Cookbook

You're reading from   Python Geospatial Analysis Cookbook Over 60 recipes to work with topology, overlays, indoor routing, and web application analysis with Python

Arrow left icon
Product type Paperback
Published in Nov 2015
Publisher
ISBN-13 9781783555079
Length 310 pages
Edition 1st Edition
Languages
Arrow right icon
Toc

Table of Contents (15) Chapters Close

Preface 1. Setting Up Your Geospatial Python Environment FREE CHAPTER 2. Working with Projections 3. Moving Spatial Data from One Format to Another 4. Working with PostGIS 5. Vector Analysis 6. Overlay Analysis 7. Raster Analysis 8. Network Routing Analysis 9. Topology Checking and Data Validation 10. Visualizing Your Analysis 11. Web Analysis with GeoDjango A. Other Geospatial Python Libraries
B. Mapping Icon Libraries
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.

You have been reading a chapter from
Python Geospatial Analysis Cookbook
Published in: Nov 2015
Publisher:
ISBN-13: 9781783555079
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime