0

I'm trying to get the boundaries from Overpass API for all counties, cities, towns, villages or hamlets for specific US states. The problem I'm having is that I sometimes get "nodes" instead of "relations" and I haven't found any truly reliable way to find the "relation". I'm quite sure one exists because OpenStreetMap seems to always be capable of showing me the relation/boundaries for some of these same places I'm trying to get.

This is pretty good but still returns a lot of nodes:

[out:json];
area["ISO3166-2"="US-NJ"]->.state;
(
    nwr(area.state)["type"="boundary"]["admin_level"="8"];
);
out geom qt;

This is also pretty good but also tends to return a lot of nodes:

[out:json];
area["ISO3166-2"="US-NJ"]->.state;
(
  nwr(area.state)["place"="city"];
);
out geom qt;

I've been using this to find relations from a node id but I've found a few cases where it doesn't return any relation even when I'm sure one exists:

[out:json];
(node(27023173);
<;
);
out geom;

1 Answer 1

0

I do thing your queries are pretty good. Let's look on the first one:

[out:json];
area["ISO3166-2"="US-NJ"]->.state;
(
    nwr(area.state)["type"="boundary"]["admin_level"="8"];
);
out geom qt;

returns mainly relations (boundaries) like:

{
  "version": 0.6,
  "generator": "Overpass API 0.7.61.5 4133829e",
  "osm3s": {
    "timestamp_osm_base": "2024-01-07T11:09:45Z",
    "timestamp_areas_base": "2024-01-07T07:01:30Z",
    "copyright": "The data included in this document is from www.openstreetmap.org. The data is made available under ODbL."
  },
  "elements": [

{
  "type": "relation",
  "id": 11998841,
  "bounds": {
    "minlat": 39.3806414,
    "minlon": -75.5442101,
    "maxlat": 39.5557416,
    "maxlon": -75.3514966
  },
  "members": [
    {
      "type": "way",
      "ref": 883001478,
      "role": "outer",
      "geometry": [
         { "lat": 39.4613019, "lon": -75.4027965 },
         { "lat": 39.4621142, "lon": -75.4008609 },
         { "lat": 39.4622233, "lon": -75.3994642 },
[...]

If you are referring to lot of nodes as those like on the image below (Cherry Chill),

that's because this node is part of boundary relation marked as admin_centre (see: https://www.openstreetmap.org/relation/962882). I'm not sure if you can filter it out directly in Overpass.

1
  • So far what I've found is that to get everything I have to use all three of the queries I listed above which is a little inefficient and takes more time. I do want to catalog some/many of the nodes as well, especially if they aren't well represented by a matching relation so I'm not against having nodes returned. It's quite possible I'm not really understanding the OpenStreetMap data model very well so I'm focusing on trying to learn it better for now.
    – HK1
    Commented Jan 7 at 15:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.