0

I have an .osm.pbf file from Geofabrik and want to extract all lakes that are not seasonal or intermittent to an SHP file, using ogr2ogr. I am currently using the following command:

ogr2ogr -where "((natural = 'water' and water = '') or (water in ('lake', 'oxbow')) and intermittent = 'no' and seasonal = '')" outfile.shp infile.osm.pbf multipolygons

The resulting SHP file is empty. If I remove the seasonal bit from the -where query, I get the desired features into the output files, but also others that are seasonal.

I took a look at the PBF file in QGIS, and there the seasonal field is showing as NULL. How do I need to modify my -where query to make this work ?

1 Answer 1

1

If the seasonal field is showing as NULL, you should check for seasonal IS NULL in the -where query, like this:

"((natural = 'water' and water = '') or (water in ('lake', 'oxbow')) and intermittent = 'no' and seasonal is NULL)"

Best to verify if the water field is in the same situation...

3
  • I tried that exact command, but using = instead of is for the NULL check - does that make any difference ?
    – TheEagle
    Dec 18, 2023 at 0:26
  • In any case, this works ! :)
    – TheEagle
    Dec 18, 2023 at 0:26
  • An explanation why = NULL doesn't work can be found here: SQL IS NULL vs = NULL
    – Pieter
    Dec 18, 2023 at 6:52

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.