This is a static archive of our old OpenStreetMap Help Site. Please post any new questions and answers at community.osm.org.

Overpass-turbo query for towns up to capital=7 and their admin_level=6 parents name

0

I'm trying to output a file in Overpass Turbo, let's assume CSV (because it seems easier to accomplish this with CSV), with:

  • All nodes in Portugal where the tag capital=yes or capital=1 or (...) or capital=7
  • For all those nodes, output the following information: name (tag), capital (tag) and coordinates and find the rel with the tag border_type=distrito (or admin_level=6) they belong to, and output it's name as well.

Example output:

namecapitallatlngparent
City_1738.123-9.123County_1
City_2238.123-9.123County_1
City_3438.123-9.123County_2
City_4438.123-9.123County_3
City_5438.123-9.123County_2


I've managed to output all info correctly except for the parent information, with this Overpass Turbo query:

[out:csv(name,capital,::lat,::lon;true;";")][timeout:250];
{{geocodeArea:Portugal}}->.searchArea;

(
  node["capital"="yes"](area.searchArea);
  node["capital"="1"](area.searchArea);
  node["capital"="2"](area.searchArea);
  node["capital"="3"](area.searchArea);
  node["capital"="4"](area.searchArea);
  node["capital"="5"](area.searchArea);
  node["capital"="6"](area.searchArea);
  node["capital"="7"](area.searchArea);
);

out body;
>;
out skel qt;

However, I'm having a hard time figuring out how to get which admin_level=6 each place belongs to. Any help would be greatly appreciated.

asked 15 Nov '20, 23:59

FSeixasPT's gravatar image

FSeixasPT
11112
accept rate: 0%


One Answer:

1

Unsure if it's possible, but try looking at recursion (to get the relation on the way) & the 'for' block command in the wiki & here: https://dev.overpass-api.de/blog/index.html (unfortunately it's isn't searchable. you'll have to go through each page individually)

Compacted version of your routine using RegEx:

[out:csv(name,capital,::lat,::lon;true;";")];
{{geocodeArea:Portugal}};
node[capital~"yes|[1-7]"](area);
out meta;

answered 17 Nov '20, 19:57

DaveF's gravatar image

DaveF
3.3k8498133
accept rate: 16%

edited 17 Nov '20, 20:02

Source code available on GitHub .