O'Reilly logo

Python Geospatial Analysis Essentials by Erik Westra

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

A working example

Let's put together everything that we have learned to write a program that can display the contents of a shapefile. This is quite a useful program to have, as you can manipulate or generate some spatial data, save the results into a shapefile, and then run this program to display the shapefile's contents as a generated map image.

We'll call our program shapeToMap.py. Create this file, and start entering the following Python code into it:

import mapnik LAYERS = [ {'shapefile' : "TM_WORLD_BORDERS-0.3.shp", 'lineColor' : "black", 'lineWidth' : 0.4, 'fillColor' : "#709070", 'labelField' : "NAME", 'labelSize' : 12, 'labelColor' : "black" } ] BACKGROUND_COLOR = "#a0c0ff" BOUNDS_MIN_LAT = 35.26 BOUNDS_MAX_LAT = 71.39 BOUNDS_MIN_LONG = ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required