3

Problem:

I am using ogr2ogr to convert osm file to shp and some features realated to the lakes are missing. I noticed for ex. lake is missing when it is flow-through lake (river is at both ends).

My result

Shapefile with some lakes but many are missing.

Question

Can someone tell me what I can do to get those missing lakes?

Part of my Osmconfig.ini

closed_ways_are_polygons=natural=water

[multipolygons]

attributes=natural

Picture:

You can only see river polygon here but there was no point to add any more layers, because I am interested in river and lakes.

rose polygon = river polygon

basemap = OSM Basemap in ArcGIS Pro

enter image description here

Edit:

I found out that when lake is within 'relation' it is correctly converted to the record in the shp, but when lake is within 'way' it is missing in shp.

Version:

GDAL 2.4.0, released 2018/12/14

5
  • 1
    Have you tried keywords for waterway such as riverbank ? Mar 11, 2019 at 16:27
  • can you share more info about the extract area (bounding box)? That's a great suggestion from @J.Monticolo and I suspect that's what is happening here.
    – Steven Kay
    Mar 11, 2019 at 21:20
  • For my answer, I've found the area on OSM and looked into the feature : openstreetmap.org/search?query=wloclawek#map=13/52.6334/19.2822 Mar 12, 2019 at 7:57
  • Have you tried to add a type (polygon)? Mar 12, 2019 at 18:11
  • Maybe try to define waterway=riverbank and waterway=river after your attributes=natural as a new line for each waterway declaration
    – Kyros Koh
    Mar 13, 2019 at 11:45

2 Answers 2

3
+100

Without a copy of your Osmconfig.ini, I've put here my solution for achieving the extraction of this Poland's water stream :

  1. Download the PBF file from Geofabrik (one of OSM Download Center)
  2. Run a terminal and use the following code :

    ogr2ogr -overwrite -skipfailures -f "ESRI Shapefile" kujawsko_pomorskie_water -sql "select * from multipolygons where hstore_get_value(other_tags, 'waterway') = 'riverbank'" -lco ENCODING=UTF-8 kujawsko-pomorskie-latest.osm.pbf

  3. Go to the new kujawsko_pomorskie_water directory and open multipolygons.shp with your favorite GIS app (mine is QGIS !)

3
  • I can't run it via terminal. C:\Users\xxxxxx>cd E:\Testowanie_osm\kujawskie C:\Users\xxxxxx>ogr2ogr -overwrite -skipfailures -f "ESRI Shapefile" kujawsko_pomorskie_water -sql "select * from multipolygons where hstore_get_value(other_tags, 'waterway') = 'riverbank'" -lco ENCODING=UTF-8 kujawsko-pomorskie-latest.osm.pbf FAILURE: Unable to open datasource `kujawsko-pomorskie-latest.osm.pbf' with the following drivers. Mar 14, 2019 at 12:48
  • Can you add in your original post your GDAL version, command ogr2ogr --version please ? Mar 14, 2019 at 13:28
  • Thanks for the version. The second command line is exected in C:\. Try this : ogr2ogr -overwrite -skipfailures -f "ESRI Shapefile" kujawsko_pomorskie_water -sql "select * from multipolygons where hstore_get_value(other_tags, 'waterway') = 'riverbank'" -lco ENCODING=UTF-8 E:\Testowanie_osm\kujawskie\kujawsko-pomorskie-latest.osm.pbf Mar 14, 2019 at 14:42
1

I had this issue also a time ago when converting .pbf to spatialite. (https://github.com/osmbe/qgis_rendering/blob/master/qgis-loves-spatialite.md)

As @J. Monticolo suggested, the problem was due to the tag waterway=riverbank. I changed that tag in OpenStreetMap to natural=water + water=river (or canal, or ...), and then it was added to the layer.

I didn't want to change every tag, so I found a sollution. I did it with QGIS DB-manager, but I think it would go with every spatialite-reading gis-software.

Activate the spatialite-DB and run following query.

insert into multipolygons (GEOMETRY, osm_id, other_tags)
select CastToMultiPolygon(BuildArea(GEOMETRY)) as geometry, osm_id, '"waterway"=>"riverbank"'
from lines
where waterway =  'riverbank'

This will search in the layer 'lines' after the way tagged as 'riverbank' and convert them to a polygon.

Your Answer

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

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