Book Image

Python Geospatial Development

By : Erik Westra
Book Image

Python Geospatial Development

By: Erik Westra

Overview of this book

<p>Open Source GIS (Geographic Information System) is a growing area with the explosion of applications such as Google Maps, Google Earth, and GPS. The GIS market is growing rapidly and as a Python developer you will find yourself either wanting grounding in GIS or needing to get up to speed to do your job. In today's location-aware world, all commercial Python developers can benefit from an understanding of GIS development gained using this book.</p> <p>Working with geo-spatial data can get complicated because you are dealing with mathematical models of the Earth's surface. Since Python is a powerful programming language with high-level toolkits, it is well suited to GIS development. will familiarize you with the Python tools required for geo-spatial development such as Mapnik, which is used for mapping in Python. It introduces GIS at the basic level with a clear, detailed walkthrough of the key GIS concepts such as location, distance, units, projections, datums, and GIS data formats. We then examine a number of Python libraries and combine these with geo-spatial data to accomplish a variety of tasks. The book provides an in-depth look at the concept of storing spatial data in a database and how you can use spatial databases as tools to solve a variety of geo-spatial problems. <br /><br />It goes into the details of generating maps using the Mapnik map-rendering toolkit, and helps you to build a sophisticated web-based geo-spatial map-editing application using GeoDjango, Mapnik, and PostGIS. By the end of the book, you will be able to integrate spatial features into your applications and build a complete mapping application from scratch.</p>
Table of Contents (19 chapters)
Python Geospatial Development
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Preface

Open Source GIS (Geographic Information Systems) is a growing area with the explosion of Google Maps-based websites and spatially-aware devices and applications. The GIS market is growing rapidly, and as a Python developer you can't afford to be left behind. In today's location-aware world, all commercial Python developers can benefit from an understanding of GIS concepts and development techniques.

Working with geo-spatial data can get complicated because you are dealing with mathematical models of the Earth's surface. Since Python is a powerful programming language with high-level toolkits, it is well-suited to GIS development. This book will familiarize you with the Python tools required for geo-spatial development. It introduces GIS at the basic level with a clear, detailed walkthrough of the key GIS concepts such as location, distance, units, projections, datums, and GIS data formats. We then examine a number of Python libraries and combine these with geo-spatial data to accomplish a variety of tasks. The book provides an in-depth look at the concept of storing spatial data in a database and how you can use spatial databases as tools to solve a variety of geo-spatial problems.

It goes into the details of generating maps using the Mapnik map-rendering toolkit, and helps you to build a sophisticated web-based geo-spatial map editing application using GeoDjango, Mapnik, and PostGIS. By the end of the book, you will be able to integrate spatial features into your applications and build a complete mapping application from scratch.

This book is a hands-on tutorial, teaching you how to access, manipulate, and display geo-spatial data efficiently using a range of Python tools for GIS development.

What this book covers

Chapter 1, Geo-Spatial Development Using Python, introduces the Python programming language and the main concepts behind geo-spatial development

Chapter 2, GIS, discusses many of the core concepts that underlie GIS development. It examines the common GIS data formats, and gets our hands dirty exploring U.S. state maps downloaded from the U.S. Census Bureau website

Chapter 3, Python Libraries for Geo‑Spatial Development, looks at a number of important libraries for developing geo-spatial applications using Python

Chapter 4, Sources of Geo-Spatial Data, covers a number of sources of freely-available geo-spatial data. It helps you to obtain map data, images, elevations, and place names for use in your geo-spatial applications

Chapter 5, Working with Geo-Spatial Data in Python, deals with various techniques for using OGR, GDAL, Shapely, and pyproj within Python programs to solve real-world problems

Chapter 6, GIS in the Database, takes an in-depth look at the concept of storing spatial data in a database, and examines three of the principal open source spatial databases

Chapter 7, Working with Spatial Data, guides us to implement, test, and make improvements to a simple web-based application named DISTAL. This application displays shorelines, towns, and lakes within a given radius of a starting point. We will use this application as the impetus for exploring a number of important concepts within geo-spatial application development

Chapter 8, Using Python and Mapnik to Generate Maps, helps us to explore the Mapnik map-generation toolkit in depth

Chapter 9, Web Frameworks for Python Geo-Spatial Development, discusses the geo-spatial web development landscape, examining the major concepts behind geo-spatial web application development, some of the main open protocols used by geo-spatial web applications, and a number of Python-based tools for implementing geo-spatial applications that run over the Internet

Chapter 10, Putting it all Together: a Complete Mapping Application, along with the final two chapters, brings together all the topics discussed in previous chapters to implement a sophisticated web-based mapping application called ShapeEditor

Chapter 11, ShapeEditor: Implementing List View, Import, and Export, continues with implementation of the ShapeEditor by adding a "list" view showing the imported Shapefiles, along with the ability to import and export Shapefiles

Chapter 12, ShapeEditor: Selecting and Editing Features, adds map-based editing and feature selection capabilities, completing the implementation of the ShapeEditor application

What you need for this book

To follow through the various examples, you will need to download and install the following software:

  • Python version 2.x (minimum version 2.5)

  • GDAL/OGR version 1.7.1 or later

  • GEOS version 3.2.2 or later

  • Shapely version 1.2 or later

  • Proj version 4.7 or later

  • pyproj version 1.8.6 or later

  • MySQL version 5.1 or later

  • MySQLdb version 1.2 or later

  • SpatiaLite version 2.3 or later

  • pysqlite version 2.6 or later

  • PostgreSQL version 8.4 or later

  • PostGIS version 1.5.1 or later

  • psycopg2 version 2.2.1 or later

  • Mapnik version 0.7.1 or later

  • Django version 1.2 or later

With the exception of Python itself, the procedure for downloading, installing, and using all of these tools is covered in the relevant chapters of this book.

Who this book is for

This book is useful for Python developers who want to get up to speed with open source GIS in order to build GIS applications or integrate geo-spatial features into their applications.

Conventions

In this book, you will find a number of styles of text that distinguish between different kinds of information. Here are some examples of these styles, and an explanation of their meaning.

Code words in text are shown as follows: "We can then convert these to Shapely geometric objects using the shapely.wkt module."

A block of code is set as follows:

import osgeo.ogr

shapefile = osgeo.ogr.Open("TM_WORLD_BORDERS-0.3.shp")
layer = shapefile.GetLayer(0)

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

from pysqlite2 import dbapi as sqlite

conn = sqlite.connect("...")
conn.enable_load_extension(True)
conn.execute('SELECT load_extension("libspatialite-2.dll")')
curs = conn.cursor()

Any command-line input or output is written as follows:

>>> import sqlite3
>>> conn = sqlite3.connect(":memory:")
>>> conn.enable_load_extension(True)

New terms and important words are shown in bold. Words that you see on the screen, in menus or dialog boxes for example, appear in the text like this: "If you want, you can change the format of the downloaded data by clicking on the Modify Data Request hyperlink".

Note

Warnings or important notes appear in a box like this.

Tip

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.

To send us general feedback, simply send an e-mail to , and mention the book title via the subject of your message.

If there is a book that you need and would like to see us publish, please send us a note in the SUGGEST A TITLE form on www.packtpub.com or e-mail .

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide on www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Tip

Downloading the example code for this book

You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the files e-mailed directly to you.

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you would report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/support, selecting your book, clicking on the errata submission form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded on our website, or added to any list of existing errata, under the Errata section of that title. Any existing errata can be viewed by selecting your title from http://www.packtpub.com/support.

Piracy

Piracy of copyright material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works, in any form, on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at with a link to the suspected pirated material.

We appreciate your help in protecting our authors, and our ability to bring you valuable content.

Questions

You can contact us at if you are having a problem with any aspect of the book, and we will do our best to address it.