Thinking in GIS
a blog about GIS from a urban geogeek living at the countryside
Python for geospatial developers
Posted: February 03, 2012Categories: geodjango, GIS, shapely, python, owslib, pyproj, qgis, mapserver, mapnik, fiona, geopy, GDAL
Feedback: View Comments
There is a recurring question at GIS mailing lists, forum and at some extent in my mailbox: what is the best way to master Python for developing geospatial applications? I myself had this question far away in 2006 when I started switching from proprietary software to Open Source, and had identified in Python the way to go.
In this post I will try to quickly summarize what is the best way to go in my opinion.
Python basics
If you are completely new to Python, first things to check out, are some very basic and popular resources, like these ones:
Obviously it does not hurt that they are, like most of resurces I will provide in this post, free resources like in beer.
Play with some Python GIS library
As soon as you have some basic skills for writing simple Python programs, start using the Python core library with some of the most popular GIS Python libraries, choosing the ones that are more relevant to the context of your background:
Before even writing any programs, test these Python APIs with a beautiful and unique feature of Python: the command line interpreter
For making it even more powerful, don't forget to check out IPython and ipdb.
Do not complicate things with an IDE, keep it simple
Don't use heavy IDE, now and later, but keep things simple using basic but powerful editors like vi and/or gedit.
They are very light and still both provide features like syntax highlight and indentation.
You will still be able to debug code in an excellent manner using pdb, or - even better - ipdb together with IPython.
Time for something more challenging
When you will be ready for mastering more challenging stuff in order to become a real Python hacker :), these resources are definitely a must-read:
- "Code Like a Pythonista: Idiomatic Python"
- the Python Enhancement Proposals (PEPs)
- "Python Cookbook" book
Some more resources on Python and geospatial software
Other Python resources, related to the geospatial sphere, worth to be mentioned are:
- the gispython mailing list
- Sean Gillies Blog
- the questions tagged "Python" @ gis.stackexchange
- the "Python Geospatial Development" book from Packt. This book gives you a really nice overview of the main things to know for Python geospatial developers: nothing you cannot figure out from free web resources, but it is really nice to have all this packed together in a single book
- the "Developing Geospatial software with Python" presentation that Alessandro Pasotti and me gave at the 2010 Italian GFOSS Day
Some best practices you should adopt
This is a quick list of best practices you should follow when developing with Python (but this is the same for other languages as well!):
- write documentation using REST, and managing and rendering it with tools like docutils and Sphinx
- write tests
- use a source control management system like git or Mercurial. If you don't want to create the SCM infrastructure yourself, use the excellent and free services by gitHub and bitbucket
Understand the jargon
Last but not least, please be sure to have a good understanding of the jargon background with these guys :)
Please, if you think I forget anything from this post, send me your feedback and I will be very happy to integrate it with yours suggestion ;) Have fun!