Country polygon is missed

Hey guys!

I’m trying to download GeoJSON of all countries’ polygons using osm2pgsql tool. For some countries there are valid country polygons in planet_osm_polygon, but for some countries there are no country polygons, just some border lines in planet_osm_line table.

For example:


select string_agg(distinct name, ', ') as name from planet_osm_polygon
where (place='country' or admin_level='2') and tags->'name:en' = 'Spain' group by osm_id;
 name 
------
(0 rows)

And there are some border lines here:


select string_agg(distinct name, ', ') as name from planet_osm_line
where (place='country' or admin_level='2') and tags->'name:en' = 'Spain' group by osm_id;
  name  
--------
 España
(1 row)


select ST_AsGeoJSON(ST_Multi(ST_LineMerge(ST_Union(way)))) as way
from planet_osm_line where (place='country' or admin_level='2') and tags->'name:en' = 'Spain' group by osm_id;

More details with images are here: https://forum.openstreetmap.org/viewtopic.php?pid=718145#p718145

Does anybody know why the issue happens? Probably I have to use some special key to convert the data correctly?
Currently I do it like that:


osm2pgsql -d osm2pgsql -H localhost -P 5432 -U postgres -W \
--hstore-all --create --cache 10240 \
--latlong --multi-geometry --keep-coastlines country.osm.pbf

Thanks for your answers.

I’m wondering if this could be because Spain is not a polygon; it is is several disjoint polygons.

My guess is that the osm2pgsql tool gets confused if the multipolygon relation is not sorted so as to keep the poygon segments in disjoint groups.

I’m not sure where support requests for that tool are taken, but I suspect it is not here.

Wachbacher’s website allows you to download all kinds of administrative boundaries in different formats via a website, without having go throug the hazzles of installing software tools

In OSM terms, a multipolygon, which is perfectly OK

Github, like (almost) everything else in OSM: https://github.com/openstreetmap/osm2pgsql

In this case there are a couple of possible reasons why there might have been a problem:

o Perhaps whatever you’re trying to do genuinely isn’t supported by osm2pgsql. Explain what you’re trying to do in a github issue and people will let you know if this is the case, or if it really should be supported and is a bug.

o The boundary of Spain has been genuinely broken in OSM very recently. There’s an ongoing discussion over who controls the sea off Ceuta and Gibraltar. Unfortunately this isn’t happening in the international boundaries forum where people could all put their point of view and discuss the issues; it’s happening via edits that tend to leave gaps in boundaries because the editors concerned aren’t so skilled at editing boundaries.

Spain is a particularly complicated boundary. As well as being a multipoligon it has Gibraltar (not part of Spain but arguably wholly enclosed within it), Ceuta et al (arguably wholly enclosed within Morocco) and Parsley Island (claimed both by Spain and Morocco, and they’ve agreed not to fight over it - currently in multipolygon terms that’s an “outer” for spain but not an “inner” for Morocco).