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

Hi, I'm pretty new to OSM. I'm working on web application in WebGL, and I have 2 major questions:

  1. I would like to know how to correctly query for city boundaries polygon. I've tried to use JSONP and http.get requests to get data form 'http://polygons.openstreetmap.fr/get_geojson.py?id=1582777' but i cant get it, because of CORS policy. This server seems to be JSONP disabled. Does any other kind of similar API exists?

  2. To get proper relations of my address i'm querying 'nominatim.openstreetmap.org' multiple times, every time constructing new url. Query for address to get city, city to get country, etc. This works but feels really tiresome. How do I query nominatim, knowing street address and getting all info that I need (city, country, continent) ?

Can you give me some hints?

asked 13 Dec '16, 09:53

Treant's gravatar image

Treant
26113
accept rate: 0%

edited 14 Dec '16, 22:54

aseerel4c26's gravatar image

aseerel4c26 ♦
32.6k18248554

Can you give examples of the Nominatim queries/URLs you're currently using?

(13 Dec '16, 15:25) mtmail

@mtmail

I'm starting with osm_id and lonlat

Getting city name -> from osm_id and lonlat: http://nominatim.openstreetmap.org/reverse?format=json&lat=51.7728321&lon=19.4528033&osm_id=246291409&accept-language=en

Getting relation -> from city name: https://nominatim.openstreetmap.org/search.php?city=Łódź&format=json

Getting polygon -> from relation http://polygons.openstreetmap.fr/get_geojson.py?id=1582777

I only have osm_id and lonlat available and I must query for city, relation, country, continent and so on. Can I do it with one url?

(14 Dec '16, 13:58) Treant

The osm_id of your initial search seems to be a street http://www.openstreetmap.org/way/246291409

To look up the hierarchy starting from the street to the country try http://nominatim.openstreetmap.org/hierarchy.php?osmid=246291409&osmtype=W and you need to parse the links in the first line. Then for each type and id you have to do more lookups.

Doing a forward search for "Łódź" is too risky as you might get the wrong place back. Searching by ids (and type N,W,R) is better.

OSM data doesn't contain continents.

The reverse search can include polygons: http://nominatim.openstreetmap.org/reverse?format=json&osm_id=1582777&osm_type=R&polygon_geojson=1 (for the polygon parameters see) https://wiki.openstreetmap.org/wiki/Nominatim#Parameters_2

State and country polygons can become large (several megabytes). In this case set &polygon_threshold to a value between 0 and 1 to simplify the polygon in the result. 0.1 is usually a good compromise.

The public Nominatim service has a usage policy (https://wiki.openstreetmap.org/wiki/Nominatim_usage_policy). Both polygon search, especially with large polygons and the hierarchy lookup are "expensive" (take more server resources than usual queries). If you crawl whole countries you will get blocked. If you send requests too fast you will get blocked. If your goal is to create a website for (paying?) customers and require high availability real-time results you should setup your own Nominatim server.

permanent link

answered 14 Dec '16, 17:23

mtmail's gravatar image

mtmail
4.8k1574
accept rate: 27%

1

Thanks for your help, this pretty much solves it.

(19 Dec '16, 08:30) Treant

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
×147
×132
×104
×92

question asked: 13 Dec '16, 09:53

question was seen: 10,660 times

last updated: 19 Dec '16, 08:30

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