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
₹799.99 ₹2323.99
Paperback
₹2904.99
Subscription
Free Trial
Renews at ₹800p/m

What do you get with a Packt Subscription?

Free for first 7 days. ₹800 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing
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 : 9781782174516
Category :
Languages :
Tools :

What do you get with a Packt Subscription?

Free for first 7 days. ₹800 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing

Product Details

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

Packt Subscriptions

See our plans and pricing
Modal Close icon
₹800 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
₹4500 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 ₹400 each
Feature tick icon Exclusive print discounts
₹5000 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 ₹400 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total 9,459.97
Python Geospatial Analysis Cookbook
₹4096.99
Python Geospatial Development Essentials
₹2457.99
Python GeoSpatial Analysis Essentials
₹2904.99
Total 9,459.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

What is included in a Packt subscription? Chevron down icon Chevron up icon

A subscription provides you with full access to view all Packt and licnesed content online, this includes exclusive access to Early Access titles. Depending on the tier chosen you can also earn credits and discounts to use for owning content

How can I cancel my subscription? Chevron down icon Chevron up icon

To cancel your subscription with us simply go to the account page - found in the top right of the page or at https://subscription.packtpub.com/my-account/subscription - From here you will see the ‘cancel subscription’ button in the grey box with your subscription information in.

What are credits? Chevron down icon Chevron up icon

Credits can be earned from reading 40 section of any title within the payment cycle - a month starting from the day of subscription payment. You also earn a Credit every month if you subscribe to our annual or 18 month plans. Credits can be used to buy books DRM free, the same way that you would pay for a book. Your credits can be found in the subscription homepage - subscription.packtpub.com - clicking on ‘the my’ library dropdown and selecting ‘credits’.

What happens if an Early Access Course is cancelled? Chevron down icon Chevron up icon

Projects are rarely cancelled, but sometimes it's unavoidable. If an Early Access course is cancelled or excessively delayed, you can exchange your purchase for another course. For further details, please contact us here.

Where can I send feedback about an Early Access title? Chevron down icon Chevron up icon

If you have any feedback about the product you're reading, or Early Access in general, then please fill out a contact form here and we'll make sure the feedback gets to the right team. 

Can I download the code files for Early Access titles? Chevron down icon Chevron up icon

We try to ensure that all books in Early Access have code available to use, download, and fork on GitHub. This helps us be more agile in the development of the book, and helps keep the often changing code base of new versions and new technologies as up to date as possible. Unfortunately, however, there will be rare cases when it is not possible for us to have downloadable code samples available until publication.

When we publish the book, the code files will also be available to download from the Packt website.

How accurate is the publication date? Chevron down icon Chevron up icon

The publication date is as accurate as we can be at any point in the project. Unfortunately, delays can happen. Often those delays are out of our control, such as changes to the technology code base or delays in the tech release. We do our best to give you an accurate estimate of the publication date at any given time, and as more chapters are delivered, the more accurate the delivery date will become.

How will I know when new chapters are ready? Chevron down icon Chevron up icon

We'll let you know every time there has been an update to a course that you've bought in Early Access. You'll get an email to let you know there has been a new chapter, or a change to a previous chapter. The new chapters are automatically added to your account, so you can also check back there any time you're ready and download or read them online.

I am a Packt subscriber, do I get Early Access? Chevron down icon Chevron up icon

Yes, all Early Access content is fully available through your subscription. You will need to have a paid for or active trial subscription in order to access all titles.

How is Early Access delivered? Chevron down icon Chevron up icon

Early Access is currently only available as a PDF or through our online reader. As we make changes or add new chapters, the files in your Packt account will be updated so you can download them again or view them online immediately.

How do I buy Early Access content? Chevron down icon Chevron up icon

Early Access is a way of us getting our content to you quicker, but the method of buying the Early Access course is still the same. Just find the course you want to buy, go through the check-out steps, and you’ll get a confirmation email from us with information and a link to the relevant Early Access courses.

What is Early Access? Chevron down icon Chevron up icon

Keeping up to date with the latest technology is difficult; new versions, new frameworks, new techniques. This feature gives you a head-start to our content, as it's being created. With Early Access you'll receive each chapter as it's written, and get regular updates throughout the product's development, as well as the final course as soon as it's ready.We created Early Access as a means of giving you the information you need, as soon as it's available. As we go through the process of developing a course, 99% of it can be ready but we can't publish until that last 1% falls in to place. Early Access helps to unlock the potential of our content early, to help you start your learning when you need it most. You not only get access to every chapter as it's delivered, edited, and updated, but you'll also get the finalized, DRM-free product to download in any format you want when it's published. As a member of Packt, you'll also be eligible for our exclusive offers, including a free course every day, and discounts on new and popular titles.