Why not ask your question on the new OpenStreetMap Community Forum?

Hello, I have a GPS coordinates list and I want to retrieve the corrisponding cities.

I'm making calls to Nominatim service, like this: https://nominatim.openstreetmap.org/reverse?format=json&lat=30.4573699&lon=-97.8247654

The response in this case is:

{"place_id":"32590342","licence":"Data ┬ę OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright","osm_type":"node","osm_id":"2785042716","lat":"30.4573699","lon":"-97.8247654","display_name":"Nagoya Steak & Sushi, 11630, RM 620, Anderson Mill, Austin, Williamson County, Texas, 78713, USA","address":{"restaurant":"Nagoya Steak & Sushi","house_number":"11630","road":"RM 620","neighbourhood":"Anderson Mill","city":"Austin","county":"Williamson County","state":"Texas","postcode":"78713","country":"USA","country_code":"us"},"boundingbox":["30.4572699","30.4574699","-97.8248654","-97.8246654"]}

So I can just get the value of city property and obtain the city. What about getting the city when the response doesn't have city property?

According to this answer, I see that I can get other properties, such as town, village, suburb, locality, hamlet and so on... but what is the best? If Nominatim response doesn't have city what property should I look for? And if even that property doesn't appear what should be the next property to try to get the value from?

Can you make a list of these properties, ordered by frequency or relevance?

In addition, what about places that doesn't have any address property? Here is some examples:

http://nominatim.openstreetmap.org/reverse?format=json&lat=19.2954697&lon=-99.1545323 http://nominatim.openstreetmap.org/reverse?format=json&lat=28.7146224&lon=77.1577398 http://nominatim.openstreetmap.org/reverse?format=json&lat=33.2038405&lon=-96.7436876 http://nominatim.openstreetmap.org/reverse?format=json&lat=28.7131567&lon=77.1466021 http://nominatim.openstreetmap.org/reverse?format=json&lat=32.2327348&lon=-81.4502764 http://nominatim.openstreetmap.org/reverse?format=json&lat=35.851869&lon=-79.0196451 http://nominatim.openstreetmap.org/reverse?format=json&lat=19.3709484&lon=-99.1666932 https://nominatim.openstreetmap.org/reverse?format=json&lat=51.6185115&lon=-0.7130883

How to deal with them?

Generally speaking, what is the best strategy to ALWAYS get a city from GPS coordinates?

asked 01 Mar '19, 16:24

Andreanovenove's gravatar image

accept rate: 0%

edited 02 Mar '19, 14:10

The ALWAYS isn't possible. You might get close, but unless you change the definition of city you have to deal with empty data in your data model.

  • Not every place (or address) in the world is assigned to a city. People living on small islands will use the name of the island as logical administrative label in their address, it doesn't make it a city.

  • A city can be multiple types of place. Especially large metropolitan areas are often both city and county, sometimes city and state (Berlin), sometimes city and country (Monaco). OSM data only allows setting one type. In rare cases two places exist in OSM data overlapping each other (same exact boundaries).

  • OSM data might be missing (explicit) assignments of streets to their city (e.g. with address tagging) or OSM data doesn't contain boundaries of a city. Other than guessing by distance it's unclear where some houses belong to.

  • Nominatim might not return the city field correctly. When a place exists as node tagged a city, but also relation (same name and/or linked) tagged a village it might return it as village. There's open issues e.g. with London boroughs, Paris Arrondissements and quarters.

https://wiki.openstreetmap.org/wiki/Key:place lists the place types and the right columns of the table have global counts. https://github.com/OpenCageData/address-formatting/blob/master/conf/components.yaml has a hierarchy of fields relevant for an address. https://github.com/openstreetmap/Nominatim/blob/master/lib/ClassTypes.php is Nominatim's internal logic to assign field names.

I would use the components.yaml, look for city aliases and if empty in the Nominatim response move up the hierarchy (county, state...).

permanent link

answered 01 Mar '19, 17:04

mtmail's gravatar image

accept rate: 27%

Thank you for your reply, I really appreciated it. Can you tell me what is wrong with places like this https://nominatim.openstreetmap.org/reverse?format=json&lat=51.6185115&lon=-0.7130883 ? As you can see the only reference for place is country! Why?

(02 Mar '19, 14:13) Andreanovenove

That might be an issue with the Nominatim logic. Can happen in remote areas (no addresses in 20+ km radius or such) but shouldn't happen in dense populated areas. Add &zoom=16 to the URL since you said you don't need housenumber level data. Even zoom=10 might work for you. The parameter is explained here http://nominatim.org/release-docs/latest/api/Reverse/

(02 Mar '19, 22:44) mtmail

It doesn't do the trick. I get "city" with default zoom (18) from here https://nominatim.openstreetmap.org/reverse?format=json&lat=52.5332647&lon=13.2065231, but not with zoom 10. Besides, I get no city, at any zoom level, with other GPS coordinates, like this https://nominatim.openstreetmap.org/reverse?format=json&lat=-1.8292911&lon=99.2568908

(03 Mar '19, 16:40) Andreanovenove

OpenStreetMap doesn't have enough data for that area. There isn't even a street mapped yet. https://nominatim.openstreetmap.org/reverse?format=html&lat=-1.8292911&lon=99.2568908

(03 Mar '19, 17:12) mtmail

Ok, I see. What do you think about the first link? Giving different zoom level doesn't always do the trick. Sometimes is convenient to use default zoom because level 10 doesn't return any city field, other times is better to use other zoom level, like 10, to get the city because default level doesn't contains any city field. So, there isn't a rule that I can follow to retrieve always an address field that is city or similar (similar administrative level).

(03 Mar '19, 19:10) Andreanovenove

Berlin is one of cases with conflicting information. https://www.openstreetmap.org/node/240109189 is tagged as both admin_level=2 (state) and place=city and that confused the reverse geocoding.

(03 Mar '19, 20:09) mtmail
showing 5 of 6 show 1 more comments
Your answer
toggle preview

Follow this question

By Email:

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



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:


question asked: 01 Mar '19, 16:24

question was seen: 7,668 times

last updated: 03 Mar '19, 20:09

powered by OSQA