OpenStreetMap logo OpenStreetMap

Extracting data from OSM

Posted by RobJN on 24 July 2012 in English.

Introduction

One of the things we have spoken about at Mappa Mercia is how to extract data from OpenStreetMap.

As the UK government makes strides to improve access to it’s location based data (e.g. the new data.gov.uk), I decided that its about time I wrote up some notes on how to get at OSM’s data.

I will be looking at two tools. Both work roughly in the same way and both return .osm files. I will discuss how to convert from osm to other formats in a later post.

MapQuest XAPI

Hosted at http://open.mapquestapi.com/xapi/ MapQuet’s tool is very intuitive. Simply select how you would like to filter the data by selecting to retrieve nodes, ways, or relations, enter a tag to filter by and pan the map to the area you are interested in.

This provides a data URL and a “run” button. The resulting output can be saved as a .osm file and used in the JOSM editor (amongst others).

Overpass API

I provide this second option as I often find MapQuest to be slow/unresponsive. We will be using the compatibility layer and constructing our own data URL. Lets look at an example:

http://www.overpass-api.de/api/xapi?way[landuse=allotments][bbox=-1.56962,52.38471,-1.500960,52.40827][@meta]

We can break this down into it’s individual components:

  1. The base url
    The base url http://www.overpass-api.de/api/xapi? is always required

  2. Feature selection
    Next we specify whether we want to retrieve just node’s, way’s or relation’s. Alternatively we retrieve everything using *

  3. Filtering by tags
    In the next part of the URL I have filtered for just those elements with the tag landuse=allotments. We could also add additional filters in the same format in order to further refine the output. Note tat the wildcard character can also be used, e.g. [landuse=allotments][name=*] would retrieve only allotments with a name tag.

  4. Bounding box
    As with the the MapQuest API, we can opt to restrict the search to just one area. The bounding box is in the same format as that of the MapQuest API so I suggest using their website to find the correct longitude and latitude values (simply copy the whole bbox section from the URL you create on MapQuests website.

  5. Include metadata Finally we add [@meta] to the end of the URL. This ensures that we retrieve all the metadata needed to be able to open the .osm file in JOSM. The metadata is also required if you intend to upload any changes back to OpenStreetMap.

Once you have constructed your URL in the same fashion, paste into your web browser and save the resulting output as a .osm file.

For more info see the wiki page.

Email icon Bluesky Icon Facebook Icon LinkedIn Icon Mastodon Icon Telegram Icon X Icon

Discussion

Log in to leave a comment