This is a static archive of our old OpenStreetMap Help Site. Please post any new questions and answers at community.osm.org.

ogr2ogr: convert all closed ways to polygons?

0

I'm converting an extracted chunk of OSM data to GeoJSON. We can use GDL ogr2ogr commands like:

ogr2ogr -f GeoJSON tmp_lines.geojson tmp_osm-solar-withreferenced.pbf lines
ogr2ogr -f GeoJSON tmp_mpoly.geojson tmp_osm-solar-withreferenced.pbf multipolygons

By default, ogr2ogr doesn't automatically convert all closed ways into polygons, only ones with certain tags which can be defined in osmconf.ini. The default is:

closed_ways_are_polygons=aeroway,amenity,boundary,building,craft,geological,historic,landuse,leisure,military,natural,office,place,shop,sport,tourism,highway=platform,public_transport=platform

How can I tell ogr2ogr that I want ALL closed ways to be treated as polygons? I know it's not always advisable in general, but in my case it's what I want, and especially I want un-tagged ways to handled like this. The closed_ways_are_polygons flag only seems to accept an explicit list.

asked 29 Apr '20, 09:27

mcld's gravatar image

mcld
81349
accept rate: 0%


One Answer:

1

It looks like you can't (the implementation just explicitly checks the listed keys):

https://github.com/OSGeo/gdal/blob/5870c3fc8ccc05ead6b9c8a5dd9fad76969fd890/gdal/ogr/ogrsf_frmts/osm/ogrosmdatasource.cpp#L1895

I imagine post processing the GeoJSON is going to be the easiest way to get what you want.

answered 29 Apr '20, 12:22

maxerickson's gravatar image

maxerickson
12.7k1083176
accept rate: 32%

Source code available on GitHub .