Search code examples
openstreetmapoverpass-api

How do I specify the admin_level for a search?


I have this query to collect all of the cities within Florida:

[out:json];
area['admin_level'='4']['name'='Florida'];
(relation['admin_level'='8'](area););out;

There are two instance of Florida at admin_level 4, though:

You can see how it returns cities in both Floridas here (you just have to switch to the Data tab and then click the Run button).

How would I rewrite this query to only query the Florida within the United States? I have 65 other searches that I have to do with similar duplication issues, so a query that I can swap out e.g. a name value for each one would be best.


Solution

  • By taking a look at the corresponding relations for Florida, UY and Florida, US you can see that there are various additional tags such as is_in:country_code and ISO3166-2. You can use one of them to limit the query to a specific country:

    [out:json];
    area['is_in:country_code'='US']['admin_level'='4']['name'='Florida'];
    (relation['admin_level'='8'](area););
    out;