[OSM-dev] libosmium and missing multipolygons

Jochen Topf jochen at remote.org
Thu Apr 21 14:48:26 UTC 2016

On Do, Apr 21, 2016 at 04:03:31 +0200, Sylvain Melin wrote:
> I wrote a C++ program using libosmium to read an osm file, filter the data
> and extract the result to different target shapefiles.
> I have a problem with some features not being written in shapefiles.
> For example, I want to extract all water bodies in the bounding box
> latmin=44 latmax=45 lonmin=-1 lonmax=0.
> In the resulting shapefile, the relation 2988 "Lit de la Dordogne" is
> missing : https://www.openstreetmap.org/relation/2988
> The osmium::Area built from this relation seems to be empty.
> area.num_rings() gives 0

If there are no rings, this means the multipolygon relation is broken in some
way. There can be many different reasons why this is the case, usually
self-intersections or gaps in the rings. Or it can be a bug in the multipolygon
assembly code. You can use "problem reporters" to give you more insight into
what libosmium thinks is wrong with the area. (Sorry, currently no sample code.
If you want to know how they work, say so, and I'll whip up some examples.)

There are a few known bugs in the libosmium MP code and I am working on an
improved versions which will be ready soon. At the moment I would suggest, you
wait a few days and then try the new code, before digging further into this.
I don't want to debug the old code any more.

Sometimes the OSM Inspector can show you where the problem is:
In this case it doesn't say anything.

> Importing my osm file in QGis or converting it with ogr2ogr gives the
> appropriate result and the relation 2988 is correctly exported into the
> shapefile.

Osmium will not export a geometry it thinks is invalid. Other programs are
often more forgiving. The reason Osmium is picky there, is that invalid
geometries can sometimes create problems when used later, creating rendering
errors or otherwise invalid data. It is better to get them fixed in OSM.
That being said, I have also though about an "just do it" mode that doesn't
give you any guarantees.

Jochen Topf  jochen at remote.org  http://www.jochentopf.com/  +49-351-31778688

More information about the dev mailing list