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

Get Python Geospatial Analysis Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.