I want to query the municipality (city or town) a given point is in, but not only its name, but also the OpenStreetMap id of the area of that city/town in order to fetch further tags from that city/town and to uniquely identify it.

For example, for the node with the id 3127879237 (located in Vienna, Austria) I would like to get back the id 3600109166 for the area of Vienna.

With Overpass and Nominatim, i could only achieve that half-way so far:

Using Overpass the following query returns all surrounding boundaries:

node(3127879237);
is_in;
area._["admin_level"]["boundary"="administrative"];
out;

One of them is the city/town boundary I am looking for, but it doesn't have any tags signalling it's the city/town and it seems like the admin_level of the municipality depends on its size and the country.

Nominatim can figure out the city/town, but it only gives back its name, which is not necessarily unique, and not its OSM-id:

https://nominatim.openstreetmap.org/lookup?osm_ids=N3127879237&format=json

Is the only way to achieve that to get the name from Nominatim and then filtering the is_in results by the name returned from Nominatim?

asked 09 Mar, 11:51

Loram's gravatar image

Loram
112
accept rate: 0%


Nominatim's /details endpoint can return a list of parent objects, each with name, osmtype, osmid. https://nominatim.openstreetmap.org/details?osmtype=N&osmid=3127879237&format=json&addressdetails=1 Ignore any items having isaddress=false. That can help you when you run your own Nominatim server. For the public nominatim.openstreetmap.org the access is discouraged as it puts a higher load on the database https://nominatim.org/release-docs/develop/api/Details/

permanent link

answered 09 Mar, 12:06

mtmail's gravatar image

mtmail
4.3k1465
accept rate: 29%

As with this example many place=city/town entities are nodes. If you're unable to rely on admin_level, you'll need to iterate the returned boundary relations to return nodes with 'admin_centre' roles. These should contain 'place=city/town'. Try expanding on this:

node(3127879237);
is_in;
rel(pivot)[boundary=administrative];
node(r:admin_centre);
out geom;
permanent link

answered 09 Mar, 13:57

DaveF's gravatar image

DaveF
1.8k617597
accept rate: 6%

edited 09 Mar, 15:26

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×635
×413
×97
×55
×11

question asked: 09 Mar, 11:51

question was seen: 117 times

last updated: 09 Mar, 15:26

powered by OSQA