Geo locating photo’s with OSM overpass API

Bear Hunt
6 min readJun 8, 2019

How can you find a specific location somewhere in the world using the overpass API from openstreetmap.

I will explain how to a specific location in the Netherlands using the overpass API.

Case: Find the locations

Where is the location of both photo’s?

Both photo’s are stills from Dutch television. They tried to hide every detail which could say something about the location such as street signs and house numbers. However, with simple techniques and the use of openstreetview the location is still verifiable.

Finding Location 1:

The second photo is taken in the village near photo 1. So in order to find the location first find location 1. In order to find the location we have to identify elements on the photo which are unique for that location. Photo 1 has several unique elements, namely:
1. the bridge
2. 5 windmills (for generating electricity)
3. canal
4. highway with in total 4 lanes

Although the Netherlands is a very small country, it still contains a large amount of possible locations where is could be. Just scrolling in google maps/earth is not very effective or fun…. In order to minimize the search area we are going to use the overpass API of Openstreetmap (OSM). On https://overpass-turbo.eu/ a OSM map is shown.

On the left is the area for querying the OSM database, on the right is the map with results.

We are going to query the OSM dataset with the identified unique elements (canal, bridge, mill and highway), from now on they are called features.

Mill

The windmills are grouped along the highway and near the canal. These mills are used for generating electricity by wind. To search all the mills in the Netherlands we want to know what to ask the database. At https://wiki.openstreetmap.org/wiki/Map_Features is a list presented with all the usable features. The features are labeled as key:value. You can search the ‘map feature’ list until you find the correct feature that represent your real life feature (bridge, canal, highway, mill). Let’s search for the kind of feature of the mill. As said before, the mill generates electricity. The main branch of electricity is ‘power’. So let’s head to the ‘power’ section.
https://wiki.openstreetmap.org/wiki/Map_Features#Power
By scrolling and looking at the photo’s you can get an idea of what the kind of power feature you’re looking for. Look for the windmill….

search for generator

When clicking on the generator link. You will go to the page were the description of ‘how to tag a power plant’. The tag description tells us that the ‘source’ of the power generation is required. Click on ‘generator:source’ to view all types of generator sources.
https://wiki.openstreetmap.org/wiki/Key:generator:source

Search the proper source type for our windmill…

By finding the source type (wind), it is possible to determine the query code for the overpass API. Click on the ‘wind’ link (https://wiki.openstreetmap.org/wiki/Tag:generator:source%3Dwind). Now, lets find a unique value for the windmill… generator:source=wind This value is unique for every windmill.

Overpass API

Head back to the overpass API at https://overpass-turbo.eu/. click on wizardgenerator:source=wind → build query. In the left part, change the timeout value to 120 or so, then click ’run’.

filling in the query and timeout value

As a result all the available tags in your database will be presented on the map. Keep in mind the search query is done on the map that is visible on your screen (the so called bbox).

By now it is possible to manually search all the selected features and compare those in google streetview versus the photo. Search for features near a canal and a highway (motorway).
However this is still a very large amount of features. So code it, so the overpass will return windmills within 100m of motorways .

JavaScript Coding:

[out:json][timeout:800];

// Get all mills in current bounding box (Netherlands)
( way[“generator:source”=”wind”]({{bbox}});
node[“generator:source”=”wind”]({{bbox}});
relation[“generator:source”=”wind”]({{bbox}});
)->.mills; // store in variable ‘mills’

// Get all highways in current bounding box and store them in the variable streets
way(around.mills:100)[highway=motorway]->.motorways;

// get mills in 100m distance for all identified relevant motorways
( node.mills(around.motorways:100);
way.mills(around.motorways:100);
rel.mills(around.motorways:100);
)->.matchingmills;

// return results, mills and motorways
(.matchingmills; .motorways;);
out geom;

mills within 100m of motorways

So… Almost there. By now we selected al the features that are within 100m of a motorway. Next thing is to filter out all the mills that are more than 500m away of a canal.

New code

[out:json][timeout:800];

// Get all mills in current bounding box (Netherlands)
( way[“generator:source”=”wind”]({{bbox}});
node[“generator:source”=”wind”]({{bbox}});
relation[“generator:source”=”wind”]({{bbox}});
)->.mills; // store in variable ‘mills’

// Get all highways in current bounding box and store them in the variable motorways
way(around.mills:250)[highway=motorway]->.motorways;

// get all canals near windmills (500m) in current bbox
way(around.mills:500)[waterway=canal]->.canals;

// get mills in 100m distance for all identified relevant motorways
( node.mills(around.motorways:250) ;
way.mills(around.motorways:250);
rel.mills(around.motorways:250);
)->.matchingmills;

// get mills in 500 distance for all identified relevant canals
// get mills in 500 distance of canals and motorways
( node.matchingmills(around.canals:500);
way.matchingmills(around.canals:500);
rel.matchingmills(around.canals:500);
)->.matchingmills;

// return results, mills and motorways
(.matchingmills;);
out geom;

The next picture shows all the mills that are near a motorway (250m) and near a canal (500m).

It’s now fun to search for photo 1 (approximate 10 locations).

The first location is……..

Houten

Photo 2

The next photo is a street. And yes there is also in this street a very unique identifier or so called feature.

can you see it now?

It’s a electricity building. These buildings are in listed in the map feature list.

substation

Apparently they are called ‘substations’. These buildings can be found by using the query wizard: ‘power=substation’

Almost found it

From here on you can use google streetview to search the correct location. There are 13 possible locations.

Conclusions

This method gives us the ability to narrow down a lot of possibilities in a short amount of time. However there are a few caveats:
1) I assume that the OSM database is accurate, complete, correct and recent
2) I have to identify the features correct (according to OSM standards)

The OSM database is not everywhere in the world accurate or complete. The Netherlands is very complete however Mali only consists of a few roads and cities. Furthermore the data needs to be recent enough, in other words the dataset must be identical to the photo.

The list with features is a large list. You need to select the correct feature otherwise it does not matter how good your query is. When you ask something different to the database, you get an different answer.

Sites to look:
Overpass Tutorial: https://vimeo.com/189554102
https://wiki.openstreetmap.org/wiki/Overpass_turbo/Wizard
https://wiki.openstreetmap.org/wiki/Overpass_API/Overpass_API_by_Example
https://overpass-turbo.eu/#
https://wiki.openstreetmap.org/wiki/Map_Features

--

--