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
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!
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.
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
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 https://forum.openstreetmap.org/viewtopic.php?id=61497 for more pointers to connect to the Belgian community (the Matrix channel is the most popular at this moment).