0

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;

asked 30 Dec '13, 22:15

Izikb's gravatar image

Izikb
1223
accept rate: 0%

edited 31 Dec '13, 07:22

stephan75's gravatar image

stephan75
12.5k454209


2 Answers:
1

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:

  1. Get a relation ID of the desired country (maybe with an editor or by walking trough the relation IDs)
  2. Request the relation object by Overpass-API
  3. Get all child objects that are refered within the relation
  4. Check if the child-ways fit seamless together and maybe fix broken ways/relations
  5. Process whatever you like...

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?
(I heard they are working on that Wikidata thing?)
It depends you understanding of country code (domain, RFC3066, ISO3166, ...) if you might happily find other lists on the net...

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

permanent link

answered 30 Dec '13, 23:25

iii's gravatar image

iii
4.9k83981
accept rate: 11%

edited 30 Dec '13, 23:28

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":

[timeout:900];
area["ISO3166-1"="us"]["admin_level"="2"];(rel(area)["admin_level"="4"];);
out qt;

what I doing wrong?

(30 Dec '13, 23:46) Izikb
0

This query is fast, but currently only results in 47 states for the US:

rel[admin_level=4]["is_in:country_code"=US];

This query is equally fast, but includes some things that you may not consider a "state". Like for the US it includes Guam.

rel[admin_level=4]["ISO3166-2"~"^US-"];

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.

permanent link

answered 12 Feb '17, 23:31

joshcoady's gravatar image

joshcoady
11112
accept rate: 0%

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:

×54
×44
×2

question asked: 30 Dec '13, 22:15

question was seen: 6,420 times

last updated: 12 Feb '17, 23:31

powered by OSQA