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;