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

How to export relation type boundary without points?

0

I am trying to export as GeoJson the boundary of the regions of Ghana. My simple query is the following:

[out:json];
area[admin_level=2][name=Ghana];
rel[boundary=administrative][admin_level=4](area);
out geom;

My challenge is that when exporting it to GeoJson I do not only get the contour but also a point or two in each region. Is there a way to get rid of it in the query? Right now, my only workaround is to remove it manually which is very slow.

asked 11 Nov '22, 20:42

gmacia's gravatar image

gmacia
11112
accept rate: 0%


One Answer:

1

Those points are the administrative centre of each region and the label of each region. The first are nodes with role admin_centre, and the second are nodes with the role label. See this wiki page for more info about type=boundary relation members.

You have to use recurse statements to get rid of those two nodes. One query that works is the following one, but there might be simpler ones:

[out:json][timeout:50];
area[admin_level=2][name=Ghana];
//We put the 16 regions relations in the .allRelations set:
rel[boundary=administrative][admin_level=4](area)->.allRelations;
//We get only the ways members of the relations, that means, the border ways of the regions,
//and we put them in the .relationWays set:
way(r.allRelations)->.relationWays;
//And now we get all the nodes of those border ways, and put them in the .waysNodes set:
node(w.relationWays)->.waysNodes;
//Now we get the union of all the three sets (relations, their ways and those ways nodes):
(
  .allRelations;
  .relationWays;
  .waysNodes;
);
//And we output all data:
out meta;

Note 1: You can't use out geom; here, because out geom; adds, among others, a sequence of "nd" members with coordinates to all relations, and therefore you would get those nodes you want to get rid of.

Note 2: We could use out body; instead of out meta; if we are not interested in metadata, like version of objets, changeset id, timestamp, and the user data of the user that last touched the object.

See this wiki page section for more info about the out standalone statement.

answered 07 Jan '23, 18:39

edvac's gravatar image

edvac
6652619
accept rate: 15%

Source code available on GitHub .