0

I need polygons of states in my Country.

After many tries, I got to this. It does return the states of my country, but there are no paths and many items that I did not want.

I've been using http://overpass-turbo.eu/ to test my queries.

[out:json][timeout:25];
{{geocodeArea:Czechia}}->.searchArea;
(
  relation["boundary"="administrative"]["admin_level"="7"](area.searchArea);
);

// print results
out body;
>;
out skel qt;

I want to know:

  • What I need to do to get polygons of results (the states in my case)
  • Why am I getting roads and other stuff when I am specifying boundary and admin_level.
  • How to do a similar query next time (I will be getting at least the same for Slovakia)
Akxe
  • 9,694
  • 3
  • 36
  • 71

1 Answers1

2

To get the polygons, you can convert the json result of your query to GeoJSON.

You can test it in http://overpass-turbo.eu/ by running the query and then clicking the Export button and choosing the GeoJSON format.

The output will contain the states and administrative centers as items of the features array. Each item will contains its polygon coordinates in geometry.coordinates.
I don't know how to filter out the administrative centers via a query, but you can easily filter out those items on the client side when processing the GeoJSON. I did not see any other unwanted data other than that.

Sample output (abbreviated for readability):

{
    ...
    "features": [
      {
        "type": "Feature",
        "properties": {
          "@id": "relation/435509",
          "ISO3166-2": "CZ-806",
          "admin_level": "7",
          "boundary": "administrative",
          "name": "okres Ostrava-město",
          ...
        },
        "geometry": {
          "type": "Polygon",
          "coordinates": [
            [
              [
                18.3400673,
                49.7592689
              ],
              [
                18.3403166,
                49.7590688
              ],
              [
                18.3406238,
                49.7586477
              ],
              ...

Regarding similar queries - it depends on the data available and is country specific.
E.g. for Slovakia, the lowest admin_level which returns areas covering the whole state is 4 and that setting returns only the regions (which is a partitioning of a higher level than the one that you are using for the Czech republic).

mcernak
  • 9,050
  • 1
  • 5
  • 13
  • The output sample is exactly what I was looking for! But nor the answer nor in the link is any code or explanation on how to get the result you showed. – Akxe Oct 26 '20 at 01:50
  • The answer contains instructions how to get that output manually - by using the export functionality available on the overpass-turbo.eu page. And if you want to do it programatically, please specify which language you are using. There are different libraries which do the JSON to GeoJSON conversion. – mcernak Oct 26 '20 at 08:41
  • I did not know my query was giving me the correct result... Thanks. The data is HUGE! Gonna have to simplify it some. But thanks... This did the job – Akxe Oct 26 '20 at 14:11