NOTICE: help.openstreetmap.org is no longer in use from 1st March 2024. Please use the OpenStreetMap Community Forum

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%


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.

permanent link

answered 07 Jan '23, 18:39

edvac's gravatar image

edvac
6652619
accept rate: 15%

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×236
×92
×67
×36
×32

question asked: 11 Nov '22, 20:42

question was seen: 1,022 times

last updated: 07 Jan '23, 18:39

NOTICE: help.openstreetmap.org is no longer in use from 1st March 2024. Please use the OpenStreetMap Community Forum