Getting OSM Data
When you want to get the most recent OpenStreetMap data, the easiest way is to download an extract from a website. There are various web services that provide data extracts for an area of your choosing.
Downloading Data Extracts
GeoFabrik is a company which specializes in working with OpenStreetMap. They provide a variety of free extracts in shapefile and raw OSM format on their download website. The advantage of downloading GeoFabrik data is that it is updated every day, and it’s easy and reliable. One disadvantage is that the data is extracted by country, and not all countries are available.
BBBike provides shapefiles and raw OSM format for cities around the world, extracted weekly. This is useful if you are looking for data extracts for a single city.
Remember that features in OpenStreetMap have an unlimited number of “free” tags, but shapefiles have attributes stored in a limited number of columns. This means that when OSM data is converted into shapefiles, only the specified tags will be included in the shapefile table. The websites listed above provide shapefiles with a default set of common tags, but if you want to extract specific tags you will need to use one of the more specialized services in the next section or learn how to export the data yourself.
The Humanitarian OpenStreetMap Team has created a service that allows users to select the area that they want to extract, and also use JOSM Presets to select custom tags to be included in the extract. The service is available to all countries where HOT works, at export.hotosm.org.
You can select your own area from any part of the world using the service at http://extract.bbbike.org/. Disadvantages are that you aren’t able to select customizable tags and that the amount of data which you can download is limited.
Overpass is an API (Application Programming Interface) for extracting data from a read-only copy of the main OpenStreetMap database which can deliver an almost arbitrary amount of data. Using a query language you can customize which subset of the data you obtain. You can either use the API directly by generating a http-request or through the overpass turbo interface.
Overpass Turbo is an interactive query generator where you should first zoom to the appropriate region on the map. Enter your query in the left field of the page and trigger any actions using the buttons at the top of the interface. If you are new to the query language then using the wizard should get you started. The OSM wiki contains a full description of the syntax of the query language as well as a collection of examples.
The map will highlight all data selected by your query which you can then modify. Press “Run” to refresh the result display. Once you are satisfied with what you see then “Export” offers a number of choices, among them raw OSM data. If the amount of data is limited you may as well access them directly after switching between map view and data view using the rightmost buttons at the top. The export option Query -> compact OverpassQL generates a hyperlink to be used for the Overpass API.
If you want to engineer a fancy query in order to obtain a subset of the data from a large area then it is a good idea to test and improve this query in Overpass Turbo on a small area. You can then zoom out to your complete region of interest and use the resulting query url directly for the API. The next section explains how you can do this.
Overpass API is a dedicated service optimized for querying but not writing OpenStreetMap data. Due to this optimization it operates very fast compared to the main database api and has virtually no limits on the amount of data transferred. Several instances of this service are available on the net, the one used in the following example also provides some information on its homepage
If you have a working query-URL for submitting an http-request to the Overpass API then a tool such as wget - available for different operating systems, see here - allows you to download the raw OSM data directly from the server and store them locally. The following snippet is a script for the bash shell common on Unix systems which obtains all data within a specified bounding box:
echo lower left latitude read ll_lat echo lower left longitude read ll_lon echo upper right latitude read ur_lat echo upper_right longitude read ur_lon echo output file read file url="http://overpass-api.de/api/interpreter?data=(node($ll_lat,$ll_lon,$ur_lat,$ur_lon);<;rel(br););out meta;" wget -O $file "$url"
What happens here (for the curious who do not want to read the full query language documentation)?
node(…) selects all nodes within a bounding box;
< recurses up fully, i.e. selects all ways containing these nodes and all relations containing these nodes and ways;
rel(br) selects all parent relations of relations obtained so far (otherwise master relations would not be obtained)
The services mentioned in this chapter are all that the average user needs to get the OSM data they want and be able to work with it in GIS software. However, you may want to learn more powerful ways of working with the data yourself. The remaining chapters in this section are quite technical, but show more advanced methods of manipulating and accessing OSM data.