NOTICE: help.openstreetmap.org is no longer in use from 1st March 2024. Please use the OpenStreetMap Community Forum

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 '21, 11:51

Loram's gravatar image

Loram
11114
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 '21, 12:06

mtmail's gravatar image

mtmail
4.8k1574
accept rate: 27%

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 '21, 13:57

DaveF's gravatar image

DaveF
3.3k8498133
accept rate: 16%

edited 09 Mar '21, 15:26

Thanks a lot! However, for other points, this query also returns the capital cities of the states and nations the point is in. The only way to filter the actual city the node is in that came to my mind is to pick the output city that is nearest to the given point in a post-processing step. Is there also a way to exclude the others from the query?

(14 Jul '21, 20:01) Loram

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:

×689
×483
×107
×65
×14

question asked: 09 Mar '21, 11:51

question was seen: 2,930 times

last updated: 14 Jul '21, 20:02

NOTICE: help.openstreetmap.org is no longer in use from 1st March 2024. Please use the OpenStreetMap Community Forum