Book Image

Python Geospatial Development - Second Edition - Second Edition

By : Erik Westra
Book Image

Python Geospatial Development - Second Edition - Second Edition

By: Erik Westra

Overview of this book

Geospatial development links your data to places on the Earth's surface. Writing geospatial programs involves tasks such as grouping data by location, storing and analyzing large amounts of spatial information, performing complex geospatial calculations, and drawing colorful interactive maps. In order to do this well, you'll need appropriate tools and techniques, as well as a thorough understanding of geospatial concepts such as map projections, datums and coordinate systems. Python Geospatial Development - Second Edition teaches you everything you need to know about writing geospatial applications using Python. No prior knowledge of geospatial concepts, tools or techniques is required. The book guides you through the process of installing and using various toolkits, obtaining geospatial data for use in your programs, and building complete and sophisticated geospatial applications in Python. Python Geospatial Development teaches you everything you need to know about writing geospatial applications using Python. No prior knowledge of geospatial concepts, tools or techniques is required. The book guides you through the process of installing and using various toolkits, obtaining geospatial data for use in your programs, and building complete and sophisticated geospatial applications in Python. This book provides an overview of the major geospatial concepts, data sources and toolkits. It teaches you how to store and access spatial data using Python, how to perform a range of spatial calculations, and how to store spatial data in a database. Because maps are such an important aspect of geospatial programming, the book teaches you how to build your own “slippy map” interface within a web application, and finishes with the detailed construction of a geospatial data editor using Geodjango. Whether you want to write quick utilities to solve spatial problems, or develop sophisticated web applications based around maps and geospatial data, this book includes everything you need to know.
Table of Contents (18 chapters)
Python Geospatial Development
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Python


Python (http://python.org) is a modern, high level language suitable for a wide variety of programming tasks. It is often used as a scripting language, automating and simplifying tasks at the operating system level, but it is equally suitable for building large and complex programs. Python has been used to write web-based systems, desktop applications, games, scientific programming, and even utilities and other higher-level parts of various operating systems.

Python supports a wide range of programming idioms, from straightforward procedural programming to object-oriented programming and functional programming.

While Python is generally considered to be an "interpreted" language, and is occasionally criticized for being slow compared to "compiled" languages such as C, the use of byte-compilation and the fact that much of the heavy lifting is done by library code means that Python's performance is often surprisingly good.

Open-source versions of the Python interpreter are freely available for all major operating systems. Python is eminently suitable for all sorts of programming, from quick one-off scripts to building huge and complex systems. It can even be run in interactive (command-line) mode, allowing you to type in commands and immediately see the results. This is ideal for doing quick calculations or figuring out how a particular library works.

One of the first things a developer notices about Python compared with other languages such as Java or C++ is how expressive the language is: what may take 20 or 30 lines of code in Java can often be written in half a dozen lines of code in Python. For example, imagine that you wanted to print a sorted list of the words that occur in a given piece of text. In Python, this is trivial:

words = set(text.split())
for word in sorted(words):
  print word

Implementing this kind of task in other languages is often surprisingly difficult.

While the Python language itself makes programming quick and easy, allowing you to focus on the task at hand, the Python Standard Libraries make programming even more efficient. These libraries make it easy to do things such as converting date and time values, manipulating strings, downloading data from websites, performing complex maths, working with e-mail messages, encoding and decoding data, XML parsing, data encryption, file manipulation, compressing and decompressing files, working with databases—the list goes on. What you can do with the Python Standard Libraries is truly amazing.

As well as the built-in modules in the Python Standard Libraries, it is easy to download and install custom modules, which can be written in either Python or C.

The Python Package Index (http://pypi.python.org) provides thousands of additional modules which you can download and install. And if that isn't enough, many other systems provide python "bindings" to allow you to access them directly from within your programs. We will be making heavy use of Python bindings in this book.

Note

It should be pointed out that there are different versions of Python available. Python 2.x is the most common version in use today, while the Python developers have been working for the past several years on a completely new, non-backwards-compatible version called Python 3. Eventually, Python 3 will replace Python 2.x, but at this stage most of the third-party libraries (including all the GIS tools we will be using) only work with Python 2.x. For this reason, we won't be using Python 3 in this book.

Python is in many ways an ideal programming language. Once you are familiar with the language itself and have used it a few times, you'll find it incredibly easy to write programs to solve various tasks. Rather than getting buried in a morass of type-definitions and low-level string manipulation, you can simply concentrate on what you want to achieve. You end up almost thinking directly in Python code. Programming in Python is straightforward, efficient, and, dare I say it, fun.