Since its inception, OpenStreetMap has crowdsourced the addition of millions of features of spatial data across the world. It’s become a fantastic resource for geographic reference data and it’s constantly being improved and updated. While it’s open source and the data is free, getting it into a usable format for analysis in desktop GIS, for example, can take a bit of effort.
Data Formats
If you’re a GIS Analyst, you’re probably used to working with file types like shapefiles, CSVs, and GeoJSON. However, if you’ve downloaded OpenStreetMap data before, you probably noticed it came with its own file extension: .OSM
. The .OSM
file format is XML that describes the data. Though it might seem frustrating that OSM has its own file format, it’s actually very useful for filtering through the vast amount of tags contained in OSM data. Sometimes you’ll see a .PBF
file, which is the compressed .OSM
file. Luckily, QGIS has built-in support for OSM files and will render the layers. Below, I’ll talk about some tools to get OSM data into QGIS and in a future blog I’ll provide a tutorial for how to export data from OSM and right into QGIS for desktop analysis.
Right in the web browser…
OpenStreetMap
You can get OpenStreetMap directly from the web browser while viewing the data. To do so, click the Export button above the window. The export tab will open on the left side of your screen with the bounding box populated with the map coordinates you are currently zoomed to. This tool seemed to fail just about every time I tried it, with the exception of very small bounding boxes the size of only a few city blocks. However, below the Export button they provide some other ways to get the data, which I’ll talk about later.
If you want to use an API…
Overpass API
The Overpass API is a read-only API that serves up selections of map data from OSM. Unlike the main OSM API, it’s optimized to retrieve data. The OpenStreetMap wikipedia can be a helpful resource for using it. The Overpass API also powers some of the other extraction tools. So if you can master using the API, you’re essentially covered.
If you want a LOT of data…
Geofabrik Downloads
Geofabrik, a software consulting firm that specializes in OSM data, offers free extracts by continent, updated weekly. This is great if you want everything for an entire continent, but they’re large files, and you can’t filter on specific tags or features.
Planet OSM
If one continent isn’t enough for you, this resource offers extracts of the entire OSM database updated weekly as XML and PBF. They also provide a changeset database, so you can identify just the features that changed, if you need to do so. Like the Geofabrik exports, it’s a lot of data and you can’t filter for specific tags or features.
If you want data for one city, metro or geographic area…
MapZen Metro Extracts
MapZen built a tool to export all OSM data at the metropolitan region level for dozens of cities around the world. Thankfully for us, they provide the data on their Metro Extracts page. The data is refreshed weekly and it’s provided in six different file formats. Anyone can contribute by creating a pull request or issue for another metro area.
BBBike.org
This extensive extraction tool allows you to create a custom bounding box to download data, or manually input the geographic coordinates. One of the great features is the ability to get the data in dozens of file formats, including shapefile, Garmin and SVG.
HOT Exports
The Humanitarian OpenStreetMap team put together this extract tool. You need an OSM account to use it, but once you have that, you’re good to go. The tool has an interactive map viewer to locate the geographic area you need then draw the bounding box. It also allows you to select which feature tags to download. This is an easy-to-use tool, but it’s only available in the countries HOT works.
If you’re working in QGIS…
Quick OSM
This is a plugin available in the QGIS plugins repository. Once installed, it has a user-friendly GUI complete with a query window. This is nice because you can construct a query to filter specific types of data in the OSM that you want to return, based on tags in the data or other elements that you deem important. Once you’ve selected the bounding geographic box, you then have the option to display only the tags present in the data in your selection, so you can narrow the data you want even further down beyond that. You can also select to filter on custom queries and based on points, lines or polygons. Once the data is selected, it populates an XML query that you can reuse later.
OSM Downloader
Another plugin for QGIS is OSM Downloader. This plugin adds a button to the QGIS toolbar that allows you to interactively select a bounding box, or define the bounding coordinates, and download an OSM file for that geographic area. You can save the layer or add it to the QGIS canvas. It’s a quick and simple way to easily get data, but you can’t filter or query the data, so you’ll get everything in the bounding box you define.
QGIS Vector Menu
OpenStreetMap support is also built directly into the QGIS application. To add data, you’ve got three options: Download Data, Import Topology from XML, and Export Topology to Spatialite. If you haven’t already downloaded any OSM data, you can pretty much work through these tools in order to get OSM data into your map. This tool will give you the option to select the extent of the data you’d like to download either by the map canvas (the geographic area you are currently zoomed to in the map), from an existing layer or manually by typing in the bounding box coordinates. Note that this will download and generate an osm file for everything within the extent — so keep in mind you may get a very large file! For Philadelphia, it took about a minute to process a 65mb file.
If you’re working in PostGIS…
Osm2pgsql
This is a command-line tool for importing OSM directly into a PostGIS-enabled PostgreSQL database.
Imposm
This is another command-line tool to import OSM-based PBF files into PostGIS, including the ability to update a database based on diff files. Currently in its third version, it’s written in Go. Previous versions are written in Python.
For more on how you can use OpenStreetMap for GIS work, read our blog on building GIS capacity in Guyana. Also, don’t forget to read and understand the copyright agreement and required citations when you are using OSM data.
OSM Data Extraction Tools
Name | Geographies | File Formats | Software |
Overpass API | Any, though large files take time | OSM XML, OSM JSON | None required |
Geofabrik | Continents | OSM, PBF | Web-based |
PlanetOSM | Global | OSM, PBF | Web-based |
MapZen Metro Extracts | Metropolitan Areas | OSM, .PBF, Osm2pgsql SHP, GeoJSON, IMPOSM SHOP, IMPOSP GEOJSON, Water and Coastline SHPs | Web-based |
BBBike.org | Bounding box to define | OSM, PBF, SHP, CSV, SVG, Garmin | Web-based |
HOT Exports | Bounding box to define, HOT countries only | SHP, Garmin, OSM, KMZ, SQlite | Web-based |
QuickOSM | Any, though large files take time | OSM | QGIS |
QSM Downloader | Any, bounding box to define | OSM | QGIS |
QGIS Vector Menu | Any, bounding box or layer to define | OSM, PBF, JSON, SHP | QGIS |
Osm2pgsql | Any, though large files take time | PostGIS | PostgreSQL, PostGIS |
Imposm | Any, though large files take time | PostGIS | PostgreSQL, PostGIS |