2

When I run ogr2ogr command to export some specific polygons from .osm.pbf file, downloaded from OSM, I get an error Warning 1: layer names ignored in combination with -sql. I use -sql tag to get get all polygons with defined amenity, leisure, bulding, ect... I also define costum osmconf.ini file for OSM driver to read some field I want to use. This step is configured usin -oo command

This is full command.

ogr2ogr -f "GPKG" osm_bldgs_exp4.gpkg us-latest.osm.pbf multipolygons -sql "select * from multipolygons where amenity is not null or leisure is not null or shop is not null or tourism is not null or historic is not null or building not in ('yes', null)" -overwrite -progress -oo CONFIG_FILE="C:\Program Files\QGIS 3.10\share\gdal\osmconf.ini"

Process continues to go on, but I am not sure what to expect in a final result.

4

In the basic ogr2ogr command the data source and layer are given as

ogr2ogr -f "GPKG" osm_bldgs_exp4.gpkg us-latest.osm.pbf multipolygons

That would convert everything from the layer "multipolygons".

When the command includes -sql the layer is defined in the SQL statement:

select * from multipolygons where ...

That overrides the layer name in the basic command. If the command is

ogr2ogr -f "GPKG" osm_bldgs_exp4.gpkg us-latest.osm.pbf multipolygons -sql "select * from points ...

you can safely expect that you will get whatever is selected by the SQL and data comes from the table "points". Remove the layer name from the basic command when you use -sql option and the warning will go away.

2
  • Thanks for the answer. Would ogr2ogr -f "GPKG" osm_bldgs_exp_test.gpkg us-latest.osm.pbf multipolygons -where "amenity is not null" -overwrite -progress also do the job? – DrJacoby Jun 22 at 9:41
  • Yes, that would do the same. Even -where "amenity is not null OR leisure is not null" should work. Parameter -sql is definitely needed if you want to use SQL functions in the selection. – user30184 Jun 22 at 12:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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