User Tools

Site Tools


Making Use of OpenStreetMap

OpenStreetMap in general

If people know of OpenStreetMap (OSM), they usually think of it as just a free alternative to Google Maps. While this is not actually wrong - OSM is a collaborative project to create a free editable map of the world - it is the geodata underlying the map that is considered the primary output of the project.

Being able to access this data - and not just a rendered representation in the form of a map - makes it handy for quite a number of applications. If you know the tools at your disposal, that is.

One interesting feature is that you can use OSM data to provide your own maps. One example can be found on my Raspberry Pi 4; it has map data for Bonn and the surrounding area that is used over on to provide a a map of that region. While the map looks exactly the same as the one at that by no means is a must - I just happen to use the same style - use the layer selector in the upper right corner select what you want to displayed. All shown on that page is hosted on my Pi. If you find that interesting please take a look at my Installing a tile server on a Raspberry Pi 4.

Please note that the Raspberry has a narrow-bandwidth connection to the Internet and uses DynDNS so frequent it gently and do not expect it to be accessible 24/7.

Bounding Boxes

If you want to put a map online, one question is: What region should I show at start. Most tools allow you to specify an extent (something along the lines of minimal/maximal longitude/latitude). Say you want to display a map of places to go in Porto, the second-largest city in Portugal. You might then want have your map start with an overview of the entire city. How to find out the extent of that city (which is called a *Bounding Box* for quite obious resons)?

That turns out to be insanely simple:

  1. Get rid of that cookie message if it happens to display.
  2. In the upper left corner there is a search input field reading *Find a place with OpenStreetMap …* - type Porto and select the one in Portugal (should be the first in the list)
  3. At the bottom-right corner (below the map) you find Copy & Paste and below that a pull-down menu that per default displays MARC. Switch it to CSV or CSV raw. The only difference between these is that the latter usually displays more (unnecessary) digits.

There you have it: The coordinates of the bouding box of Porto are -8.691294,41.138351,-8.552009,41.185935.

The meaning of these four values are

-8.691294 8.691294° W Westernmost longitude
-8.552009 8.552009° W Easternmost longitude
41.138351 41.138351° N Southernmost latitude
41.185935 41.185935° N Northernmost latitude

Borders, City Limits and the like

Let us again assume, you want to display a map of places to go in Porto. You may then like to display Porto's city limits. How to do that? Now that is a bit more involved than finding the bounding box.

  1. Zoom in on the Iberian peninsula (otherwise the search will find nonsense)
  2. Click on Administrative Boundary Porto, Área Metropolitana do Porto, North, Portugal
  3. Copy the relation number (that's 3372453)
  4. Under Polygon Creation enter the relation number (3372453) into the Id of relation field and submit.
  5. Now you can download the city limits in different formats. The formats include WKT and GeoJSON. If you rather need KML you can use converters like

Curious what the above data yield?

Extracting Information using overpass API

What does the Porto example lack so far? Obviously the actual places to go. Let us extract a couple of datasets:

  • bar
  • biergarten (to my great surprise, according to OSM Porto actually has a beer garden)
  • cafe
  • nightclub
  • pub

First head to On the right you see a map, on the left you may enter database request.

You may wish to read about Overpass API in the OpenStreetMap Wiki before constructing your own requests, the one I suggest is dead simple:

  (41.138351, -8.691294, 41.185935, -8.552009);

For the other kinds of amenity simply replace bar by biergarten, cafe, nightclub and pub. Note that the OSM wiki describes what else you can search for.

By now, the numbers should look familiar. They are again the bounding box, in this case it limits the database request to that region. You could also limit the request to Porto itself but that requires a slightly more involved query.

At the top of the page you find Export that (among other formats) allows you to export the query result as GeoJSON.

Besides simplicity there is another reason for using different JSON files for different kinds of points of interest (POIs for short)? There actually is: It makes it easy to use different markers for different kinds of POIs. See If you are interested in the page's source head to

Please note that the git repository is also hosted on my Raspberry Pi so it may not be available 24/7. Also don't expect great bandwidth.

Querying the OpenStreetMap Database Using Overpass QL

As pointed out earlier, the core of OpenStreetMap is a geographical database. Like any other database it provides means to query it: The Overpass API that allows you to query the database using Overpass QL, the Overpass Query Language. Under the latter link you find some quite extensive documentation of Overpass QL, to try out queries you can use overpass turbo.

Some queries to try

Say you want to obtain the city limits of Bonn as a geometry.

out geom;

For comparison go to, search for Bonn and select County Boundary Bonn, North Rhine-Westphalia, Germany (may display in your local language).

For what follows we need other data on Bonn, the result of an area query

area[name=Bonn][admin_level=6]; out;

This result cannot be shown on a map, overpass turbo should automagically switch to Data to display it.

Query stolpersteine within a rough bounding box for Bonn:

out meta;

You may notice that the query returns stolpersteine outside of Bonn, so let's limit the results to the area of Bonn:

out meta;

You could do without the bounding box but it makes the query faster and reduces the strain on the overpass turbo server.

Here is how the result will look like (shrunk screenshot):

The following was a query I made for finding out which stolpersteins around Bonn had mismatching pairs of memorial:text and inscription - something that seemingly is beyond the capabilities of JOSM (for easier finding them in JOSM I enriched the result with all the attributes):

( node["memorial"~"stolperstein"]["memorial:text"]["inscription"](if:(t["memorial:text"] != t["inscription"]));
  way["memorial"~"stolperstein"]["memorial:text"]["inscription"](if:t["memorial:text"] != t["inscription"]);
  rel["memorial"~"stolperstein"]["memorial:text"]["inscription"](if:t["memorial:text"] != t["inscription"]);
out body;
out skel qt;
gis/making_use_of_openstreetmap.txt · Last modified: 2020/11/18 22:08 by jupp