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 pyshp, geojson, and pandas

These specific libraries are for specific formats that make our life easier and simpler than using GDAL for some projects. pyshp will work with shapefiles, geojson with GeoJSON, and pandas with all other textual data types in a structured manner.

pyshp is pure Python and is used to import and export shapefiles; you can find the source code for pyshp here at https://github.com/GeospatialPython/pyshp. The pyshp library's sole purpose is to work with shapefiles. GDAL will be used to do most of our data's in/out needs, but sometimes, a pure Python library is simpler when working with shapefiles.

geojson is the name of a Python library and also a format, making it a little confusing to understand. The GeoJSON format (http://geojson.org) is becoming ever more popular and to this extent, we use the Python geojson library to handle its creation. You will find it on Python Package Index (PyPI) if you search for geojson. As you would expect, this will help us create all the different geometry types supported in the GeoJSON specifications.

pandas (http://pandas.pydata.org) is a data analysis library that structures your data in a spreadsheet-like manner for further computations. Since our geospatial data comes from a broad set of sources and formats, such as CSV, pandas helps work with the data with minimal effort.

Getting ready

Enter your virtual environment using the following command:

$ workon pygeoan_cb

Your prompt should now look like this:

(pygeoan_cb)mdiener@mdiener-VirtualBox:~$

How to do it...

The three installations are as follows:

  1. Pyshp will first be installed by simply using pip as follows:
    $ pip install pyshp
    
  2. Next, the geojson library will be installed using pip:
    $ pip install geojson
    
  3. Finally, pip will install pandas:
    $ pip install pandas
    

To test your installation of pyshp, use the import shapefile type. The output should look like what is shown in the following output:

(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 shapefile
>> import geojson
>> import pandas

Note

The import shapefile statement imports the pyshp library; unlike the other libraries, the import name is not the same as the installation name.

How it works...

As seen in the other modules, we've used the standard installation pip package to execute installations. There are no other dependencies to worry about, making for fast progress.

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