Overpass query to get the id of country boundaries

I am trying to get the ids of the closed boundaries of all countries (one relation id for each country).
Until now, I have this overpass query:

[out:csv(::id)];
(
  relation["boundary"="administrative"]["admin_level"="2"];
);
out ids;

However, there are some “boundary” relation sections in some countries (France, Germany, Spain) that are affecting the list (relation ids: 102666, 51239, 90333, 90340, etc.).

How can I identify the relation for each country? I have also tried the isClosed function, but probably I didn’t use correctly.

I usually add “ISO3166-1” as another filter:

[out:csv(::id)];
relation["boundary"="administrative"]["admin_level"="2"]["ISO3166-1"];
out ids;

At this time, you get 216 relations, which seems reasonable.

Also, IIRC, is_closed() is only defined for ways but not relations.

Edit: you can also add ["type"="boundary"] as per below answer, it won’t change the result, though.

2 Likes

Those other relations are type=multilinestring, you can get rid of them by checking for type=boundary:

[out:csv(::id)];
(
  relation["type"="boundary"]["boundary"="administrative"]["admin_level"="2"];
);
out ids;
2 Likes