Reverse geocoding: XY to (Multi)Polygon (city)


For the most common countries, I’m handling this with a subset of the GADM shapefiles imported into a database, but I didn’t want to import all the cities of the world.

For this small scale project, I’ve been looking at the Nominatim API for fallback situations.

What I’m looking to accomplish: the user pinpoints his location (point). When I use Nominatim, it grabs the most nearby address if I use reverse geocoding; from which I can derive the city border in a second request. In some situations though; the nearest address is in the town or city right next to the one where the pin was put. But sometimes this doesn’t work at all.

Now, I also explored using search with coordinates. For some reason, Nominatim still picks a neighbour town :expressionless:

Which OSM API could I use to simply derive the (Multi)Polygon of a town or city simply from a Point, preferably in GeoJSON?

Thanks in advance! :slight_smile:

Here’s an example for which the method above fails:

Result mentions Bad Berleburg. If you look that up, the point is not in the polygon for Bad Berleburg.
Somehow I should derive a boundary for Bad Laasphe I guess (so from the point I actually need to derive this boundary, for which I don’t know the name in advance without reverse geocoding)

As no one has answered, I’m going to speculate that there is no OSM funded API that does what you want. I’d further speculate, without having studied its internals, that Nominatim relies on pre-computing the containment relationships for the finite number of OSM objects, rather than having to determine them, on the fly, for one of the infinite number of possible latitude/longitude pairs.

Does the question mark on the right side of not something similar? How does it work?

Doesn’t it use overpass?
See for more infos.
Search for around …

Yes, that’s correct, at least if you’re looking at the “Enclosing objects” section on the result screen. It uses is_in(…) to determine all areas a given lat/lon position is in - see

Thanks, I’ll look into that API and see if I can get something working (and share it)

I can’t seem to get to put this together. Could someone help me with that OverPass query?

Let’s say I have a random XY in Ghent, and I want to fetch the geometry of the city border. Preferably as an area (Polygon). I understand areas are a concept within OverPass, not OSM, when it comes to administrative boundaries, but I just can’t seem to figure it out :s

Anyone knows how to do it, please?

Or with another OpenStreetMap (-based) API ?

If you use OverPass Turbo, under “load” (“laden” in Dutch), you will see an examples. Pick “Where am I”.
This query returns all administrative boundaries around the centre of the currently displayed map.

p.s. feel free to join the Belgian chat/matrix/riot channel . See for more pointers to connect to the Belgian community (the Matrix channel is the most popular at this moment).

Can’t believe the answer turns out to be so simple. Browsed their page with examples, but never knew there were examples right under “Load”.

I’ll check now how to get the geometry. Thank you very much!