O'Reilly logo

Python Geospatial Analysis Cookbook by Michael Diener

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

Converting an OpenStreetMap (OSM) XML to a Shapefile

OpenStreetMap (OSM) has a wealth of free data, but to use it with most other applications, we need to convert it to other formats, such as Shapefile or PostgreSQL PostGIS databases. This recipe will use the ogr2ogr tool to perform the conversion for us within a Python script. The benefit of this is, again, simplicity.

Getting ready

To get started, you will need to download the OSM data at http://www.openstreetmap.org/export#map=17/37.80721/-122.47305 and save the file (.osm) to your /ch03/geodata directory. The download button is located on the left-hand side bar and, when pressed, it should immediately start the download (refer to the following screenshot). The area we are testing is in San ...

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