[gdal-dev] OSM driver won't generate feature for relation
Tim Harris
Tim.Harris at digitalglobe.com
Wed Jul 12 14:31:19 PDT 2017
I'm trying to extract water vectors from OSM using my own local Overpass API server and OGR. It works for the most part, but there are some water features missing in my output. One particularly large omission is Lake Huron.
I put an example OSM file here: https://s3.amazonaws.com/gdal-osm-data/lake_huron.osm
I can see a <relation> in the file that corresponds to Lake Huron, it's the last element near the end of the file, <relation id="1205151">. It's got 12797 <member> elements that reference the 12797 <way> elements in the file (I think).
I've been looking at http://www.gdal.org/drv_osm.html and saw a few tips, like setting OGR_INTERLEAVED_READING to YES and using the example do/while loop. Here's my Python translation:
import gdal
import ogr
import geojson
gdal.SetConfigOption("OGR_INTERLEAVED_READING", "YES")
ds = ogr.Open("test_water.osm")
feats = []
nonempty = True
while nonempty:
nonempty = False
for i in range(0, ds.GetLayerCount()):
layer = ds.GetLayerByIndex(i)
feat = layer.GetNextFeature()
while feat is not None:
feats.append(feat)
nonempty = True
feat = layer.GetNextFeature()
with open("output.geojson", "w") as fobj:
fc = geojson.FeatureCollection(features=[geojson.loads(feat.ExportToJson()) for feat in feats])
geojson.dump(fc, fobj)
When I load output.geojson into QGIS and look at the line strings and polygons, I don't see a multipolygon for Lake Huron. I do see the outline as a bunch of line strings, but no polygon. I get a similar result if I load the OSM file into QGIS directly... no lake polygon. Just a few random smaller polygons around the perimiter. It seems like OGR just isn't producing a feature for that last relation.
I've tried messing around with osmconf.ini, including using the one from the QGIS plugin "QuickOSM". My most recent version of that file is here: https://s3.amazonaws.com/gdal-osm-data/osmconf.ini
Is there some setting I'm missing in osmconf.ini that would result in a multipolygon for the lake? The relation is there and it has a "type" tag set to "multipolygon".
This electronic communication and any attachments may contain confidential and proprietary information of DigitalGlobe, Inc. If you are not the intended recipient, or an agent or employee responsible for delivering this communication to the intended recipient, or if you have received this communication in error, please do not print, copy, retransmit, disseminate or otherwise use the information. Please indicate to the sender that you have received this communication in error, and delete the copy you received.
DigitalGlobe reserves the right to monitor any electronic communication sent or received by its employees, agents or representatives.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20170712/270b7128/attachment.html>
More information about the gdal-dev
mailing list