Published
I've recently been working on a map of house prices in Amsterdam and I have data at the address level.
While this is useful to know on its own, for the sake of visualizing data on a map, I wanted to know which building this address belongs to so I can color the building instead of only adding a marker to the map.
Unfortunately in OpenStreetMap, residential addresses don't
always have a relationship to the
building
they are part of. See for example, the address node in the image
below.
To find the building an address belongs to, you can query the Overpass API, which is very powerful, but also far from intuitive and easy to write by hand.
After failing to find a ready-made query online and after failing to get anything useful out of ChatGPT, I came across this post by Leigh Dodds which helped me write the query I needed.
The query below will return the building
area that contains an
address node.
(
// find the node
node({osm_id})->.home;
// find all areas the node is in
.home is_in ->.some_area;
// filter areas that are tagged as "building"
way(pivot.some_area)["building"];
>;
);
out;
Using this query and the node ID from my example above, we can finally find the building. Here's a link to Overpass Turbo with the query pre-filled.