0

I am downloading an osm.pbf file from the Geofabrik download server and running the following command:

ogr2ogr -f GPKG norcal-latest-multipolygons.gpkg norcal-latest.osm.pbf -sql "SELECT * FROM multipolygons"

The resulting output seems to be missing several polygons. For example, way-404851503 is absent. However, if I edit the query to specifically filter on that one record in particular, it is able to find it:

ogr2ogr -f GPKG norcal-latest-multipolygons.gpkg norcal-latest.osm.pbf -sql "SELECT * FROM multipolygons where osm_way_id=404851503"

I found that if I change the query to the following, there are an additional 1,821 records, including the specific polygons that I were missing. I think that this is all of the records.

select * from multipolygons where osm_way_id is not null UNION ALL SELECT * FROM multipolygons where osm_id is not null

All of the missing records I have found so far appear to be closed ways. How can this happen? Under what circumstances would running a query with no filter be excluding records? How can I be sure that the resulting GPKG includes ALL multipolygons from the osm.pbf file?

1 Answer 1

1

The way that you used as an example is this https://www.openstreetmap.org/way/404851503 It is a closed way that consists of 109 points. It acts in an "outer" role in a relation "Golden Gate National Recreation Area" https://www.openstreetmap.org/relation/13160225. That relation is of type "boundary" and it should be understood by GDAL https://gdal.org/drivers/vector/osm.html

multipolygons : "relation" features that form a multipolygon (type = 'multipolygon' or type = 'boundary'), and "way" features that are recognized as area.

However, this relation has also members which are of type "subarea", for example China Beach https://www.openstreetmap.org/relation/2173408 and that subarea itself is a multipolygon.

I believe that the GDAL OSM driver is not capable enough for handling this kind of nested relations. The issue in this conversion is not that the way/404851503 is missing from multipolygon, the issue is that relation/13160225 that includes your way is missing.

To the question "How can I be sure that the resulting GPKG includes ALL multipolygons from the osm.pbf file" I fear the answer is unfortunately that you cannot. The GDAL OSM driver tries to convert OSM objects into traditional GIS features but with OSM data model it is possible to make very complicated constructions. GDAL should parse correctly simple multipolygons (relation type=multipolygon) when they are constructed as documented https://wiki.openstreetmap.org/wiki/Relation:multipolygon.

Other tools like osm2pgsql may do better job with complicated relations https://wiki.openstreetmap.org/wiki/Converting_map_data_between_formats.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.