Book Image

Python Geospatial Analysis Cookbook

Book Image

Python Geospatial Analysis Cookbook

Overview of this book

Table of Contents (20 chapters)
Python Geospatial Analysis Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Other Geospatial Python Libraries
Mapping Icon Libraries
Index

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 Francisco, just before the Golden Gate Bridge.

If you choose to download another area from OSM, feel free but make sure you take a small area similar to my example. If you select a larger area, the OSM web tool will give you a warning and disable the...