Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Python GeoSpatial Analysis Essentials
Python GeoSpatial Analysis Essentials

Python GeoSpatial Analysis Essentials: Process, analyze, and display geospatial data using Python libraries and related tools

eBook
$20.98 $29.99
Paperback
$38.99
Subscription
Free Trial
Renews at $19.99p/m

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Table of content icon View table of contents Preview book icon Preview Book

Python GeoSpatial Analysis Essentials

Chapter 2. Geospatial Data

In this chapter, we will focus on the data used for geospatial analysis. You will learn more about the nature of geospatial data, and discover some of the major websites you can use to obtain geospatial datasets for free. We will then look at the ways in which you can read and write geospatial data using Python.

In particular, this chapter will cover the following topics:

  • Why having high quality geospatial data is important
  • The various types of geospatial data you are likely to encounter
  • Major sources of freely-available geospatial datasets
  • How to read and write geospatial data using the GDAL/OGR library
  • How to work with Spatial Reference Systems
  • Geospatial data errors and how to fix them

Let's start by looking at why having high-quality geospatial data is important.

Geospatial data quality

Imagine that you are writing a program where you need to display the location of each city and town on top of a raster basemap. You dutifully obtain a nice raster datasource to use for the basemap, and then search the Internet for a source of city and town data. You choose the National Geospatial Intelligence Service (NGIS) website to download a database of place names, which you then draw onto your map. This database includes, among other things, the latitude and longitude of each place name:

Location

Latitude

Longitude

Abache

7.3551

7.6407

Abacheke

5.50372

6.729519

Abacher

13.816667

20.816667

Abacheri

14.183333

41.5

Abachi

7.3551

7.6407

...and so on

  

So far so good, but when your program is complete, the locations look suspiciously regular when the user zooms in on your map:

Geospatial data quality

If you were to draw a grid on top of this map, you can see exactly what the problem is:

Geospatial data quality

As you can see, the locations are regularly spaced—despite there...

Types of geospatial data

In the previous chapter, we looked briefly at some of the more common formats used to store and transfer raster and vector geospatial data. Let's now look at some of the more important types of geospatial data you are likely to encounter.

Shapefiles

As we saw in the previous chapter, a shapefile is a collection of files on disk, which together hold a set of geospatial features along with their attributes and geometries. For example, the following illustration shows the data stored in a typical shapefile:

Shapefiles

Because the shapefile format has been around for many years, and dates back to the dBase days, a single shapefile is made up of several individual files. Typically, these files are combined into a ZIP archive for distribution.

Shapefiles are hugely popular because they make it so easy to store and distribute geospatial data. Practically every GIS system and library that works with geospatial data is able to understand the shapefile format.

Shapefiles, however, do...

Sources of freely available geospatial data

Now that you understand the importance of having the appropriate geospatial data and have learned about the major types of data that you will want to use, let's look at some of the places where you can obtain the data you'll need.

There are some situations where you may need to purchase geospatial datasets. One example of this is when looking for ZIP code boundaries in the USA; this information is proprietary to the US Postal Service (USPS), and accurate versions can only be obtained by purchasing a suitable dataset from a vendor licensed by the USPS to sell this data. However, this is the exception: in almost every other case, you can obtain, modify, and use geospatial data for free.

Let's now take a look at some of the major websites you will want to use when looking for geospatial data.

Natural Earth Data

The Natural Earth Data website (http://naturalearthdata.com) is a comprehensive source of high-quality and freely available geospatial...

Reading and writing geospatial data using Python

Since we will be using the GDAL/OGR library to access geospatial data, let's take a closer look at how you can read and write both vector-format and raster-format data using this library.

Reading vector data

In the previous chapter, we wrote a simple program that reads the features out of a shapefile. Here is a copy of that program:

import osgeo.ogr
shapefile = osgeo.ogr.Open("TM_WORLD_BORDERS-0.3.shp")
layer = shapefile.GetLayer(0)
for i in range(layer.GetFeatureCount()):
    feature = layer.GetFeature(i)
    feature_name = feature.GetField("NAME")
    geometry = feature.GetGeometryRef()
    geometry_type = geometry.GetGeometryName()
    print i, feature_name, geometry_type

Let's take a closer look at how this program works, and more generally, how to read vector-format data using the OGR library.

When reading geospatial data, the osgeo.ogr.Open() function takes just a single parameter: the name of the dataset to...

Dealing with spatial reference systems

One of the things that can be quite confusing when you start working with geospatial data is the notion of a spatial reference system. Imagine that you're running a search-and-rescue operation, and are given the location of a plane crash as a coordinate, for example:

(-114.93, 12.478)

What do these numbers mean? Are these values a latitude and longitude, or are they perhaps a number of kilometers away from a given reference point? Without understanding how these coordinates translate to a point on the Earth's surface, you'd have no way of knowing where to send your rescuers.

Note

Spatial reference systems are sometimes referred to as coordinate reference systems. Don't worry: these two terms refer to the same thing.

To understand the concept of spatial reference systems, you first need to learn a bit about mapping theory. Maps are an attempt to draw the three-dimensional surface of the Earth on a two-dimensional Cartesian plane:

Dealing with spatial reference systems

To convert...

Geospatial data quality


Imagine that you are writing a program where you need to display the location of each city and town on top of a raster basemap. You dutifully obtain a nice raster datasource to use for the basemap, and then search the Internet for a source of city and town data. You choose the National Geospatial Intelligence Service (NGIS) website to download a database of place names, which you then draw onto your map. This database includes, among other things, the latitude and longitude of each place name:

Location

Latitude

Longitude

Abache

7.3551

7.6407

Abacheke

5.50372

6.729519

Abacher

13.816667

20.816667

Abacheri

14.183333

41.5

Abachi

7.3551

7.6407

...and so on

  

So far so good, but when your program is complete, the locations look suspiciously regular when the user zooms in on your map:

If you were to draw a grid on top of this map, you can see exactly what the problem is:

As you can see, the locations are regularly spaced—despite there being lots of precision...

Types of geospatial data


In the previous chapter, we looked briefly at some of the more common formats used to store and transfer raster and vector geospatial data. Let's now look at some of the more important types of geospatial data you are likely to encounter.

Shapefiles

As we saw in the previous chapter, a shapefile is a collection of files on disk, which together hold a set of geospatial features along with their attributes and geometries. For example, the following illustration shows the data stored in a typical shapefile:

Because the shapefile format has been around for many years, and dates back to the dBase days, a single shapefile is made up of several individual files. Typically, these files are combined into a ZIP archive for distribution.

Shapefiles are hugely popular because they make it so easy to store and distribute geospatial data. Practically every GIS system and library that works with geospatial data is able to understand the shapefile format.

Shapefiles, however, do have...

Left arrow icon Right arrow icon

Description

If you are an experienced Python developer and wish to get up-to-speed with geospatial programming, then this book is for you. While familiarity with installing third-party Python libraries would be an advantage, no prior knowledge of geospatial programming is required.

Who is this book for?

If you are an experienced Python developer and wish to get up-to-speed with geospatial programming, then this book is for you. While familiarity with installing third-party Python libraries would be an advantage, no prior knowledge of geospatial programming is required.

What you will learn

  • Understand the key geospatial concepts and techniques needed to analyze and work with geospatial data
  • Learn how to read and write geospatial data from within your Python code
  • Use PostGIS to store spatial data and perform spatial queries
  • Use Python libraries to analyze and manipulate geospatial data
  • Generate maps based on your spatial data
  • Implement complete geospatial analysis systems using Python
  • Use the Shapely and NetworkX libraries to solve problems such as distancearea calculations, finding the shortest path between two points, buffering polygons, and much more

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Jun 23, 2015
Length: 200 pages
Edition : 1st
Language : English
ISBN-13 : 9781783553891
Category :
Languages :
Tools :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Product Details

Publication date : Jun 23, 2015
Length: 200 pages
Edition : 1st
Language : English
ISBN-13 : 9781783553891
Category :
Languages :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
$199.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts
$279.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total $ 126.97
Python Geospatial Analysis Cookbook
$54.99
Python Geospatial Development Essentials
$32.99
Python GeoSpatial Analysis Essentials
$38.99
Total $ 126.97 Stars icon
Banner background image

Table of Contents

7 Chapters
1. Geospatial Analysis and Techniques Chevron down icon Chevron up icon
2. Geospatial Data Chevron down icon Chevron up icon
3. Spatial Databases Chevron down icon Chevron up icon
4. Creating Maps Chevron down icon Chevron up icon
5. Analyzing Geospatial Data Chevron down icon Chevron up icon
6. Building a Complete Geospatial Analysis System Chevron down icon Chevron up icon
Index Chevron down icon Chevron up icon

Customer reviews

Rating distribution
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
(2 Ratings)
5 star 0%
4 star 100%
3 star 0%
2 star 0%
1 star 0%
Zakary Hoyt Jul 23, 2015
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
I purchased the book as a reference for an earthquake acceleration mapping project. The booked worked great for that purpose. The step by step instructions for installing all of the required python modules were especially informative. The code examples were also helpful. When I started the project I was new to python, and the book was accessible to my skill level. I would definitely recommend this book to anyone who is working with data that has a geospatial component.
Amazon Verified review Amazon
Karhunen Jani Aug 05, 2015
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
Overall, the book is well written and keeps me interested as it progresses chapter by chapter. The books gives you the toolset needed to start geospatial analysis with Python by providing examples to try out. It covers briefly some of the theory and concepts behind the code, but does not go very deep. If you are looking for an introduction to GIS and geospatial analysis in general, there are more theory oriented and well-suited books on the subject. If you like more an hand-on approach and quick start, I believe this book will have you covered. I deduct one star, because the code examples should have been more thoroughly tested by the author and review team, since there are few errors.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.