Chapter 1. Geo-Spatial Development Using Python

This chapter provides an overview of the Python programming language and geo-spatial development. Please note that this is not a tutorial on how to use the Python language; Python is easy to learn, but the details are beyond the scope of this book.

In this chapter, we will cover:

  • What the Python programming language is, and how it differs from other languages
  • An introduction to the Python Standard Library and the Python Package Index
  • What the terms "geo-spatial data" and "geo-spatial development" refer to
  • An overview of the process of accessing, manipulating, and displaying geo-spatial data
  • Some of the major applications for geo-spatial development
  • Some of the recent trends in the field of geo-spatial development

Python

Python (http://python.org) is a modern, high-level language suitable for a wide variety of programming tasks. Technically, it is often referred to as a "scripting" language, though this distinction isn't very important nowadays. Python has been used for writing 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 have an array of latitude and longitude values you wish to process one at a time. In Python, this is trivial:

for lat,long in coordinates:
    ...

Compare this with how much work a programmer would have to do in Java to achieve the same result:

for (int i=0; i < coordinates.length; i++) {
    float lat = coordinates[i][0];
    float long = coordinates[i][1];
...
}

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 that 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.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.226.4.191