I need to get a list of states for every country(by country code). it's possible with overpass QL? I wrote this code and it's works fine. but it's takes a long time to be executed for countries like "us": [timeout:900]; area["ISO3166-1"="us"]["admin_level"="2"];(rel(area)["admin_level"="4"];); out qt; |
Well indeed it is possible, but not that easy. The reason is that the country informations are attached at the country boundaries and the way how OSM models them are the so called 'relations'. In short this are container objects that can hold other OSM objects (here: the OSM ways that create the outer shape of a country). For boundaries there is a boundary relation that holds all the single ways of the (shared by 2..n countries!) borders. Unfortunatly esp. on national level, the meaning of the levels can be different, so you might need to check/adapt your request per country. So you need:
Steps 3,4 are optional if you want to do some real geospatial processing or rendering of the shape. In short: If you really just need a (string) list, it might be easier to get it from Wikipedia? For Germany we have this pretty nice page to get GeoJSON of our countries/cities/... http://ags.misterboo.de but AFAIK there is nothing similar with global coverage, not even at http://openstreetmapdata.com/data answered 30 Dec '13, 23:25 iii 1
Thanks! I wrote this code and it's works fine. but it's takes a long time to be executed for countries like "us":
what I doing wrong?
(30 Dec '13, 23:46)
Izikb
|
This query is fast, but currently only results in 47 states for the US:
This query is equally fast, but includes some things that you may not consider a "state". Like for the US it includes Guam.
The reason both of these queries are fast is because it is just looking up the info based on tags rather than determining if the boundaries are within the country's boundary. Depending on your needs, they may be good enough. answered 12 Feb '17, 23:31 joshcoady |