OGR2OGR Geopackage – Creating GPKG with Many Layers Using ogr2ogr

gdalgeopackageogr2ogr

I am trying to merge many shapefiles into a single gpkg using ogr2ogr (version 3.0.2).

The command I am using is:

ogr2ogr dst.gpkg src.shp -nln layerOne
ogr2ogr dst.gpkg src.shp -nln layerTwo

BUT when I run ogrinfo it says my dst.gpkg has only layerTwo.

Best Answer

You are overwriting dst.gpkg every time you run ogr2ogr. From the geopackage documentation:

For adding new layers into existing geopackage run ogr2ogr with -update.

So do:

ogr2ogr -f GPKG dst.gpkg src.shp -nln layerOne
ogr2ogr -f GPKG -update dst.gpkg src.shp -nln layerTwo

Or if all source shapefiles are in a single directory:

Translation of a directory of shapefiles into a GeoPackage. Each file will end up as a new table within the GPKG file. The file filename.gpkg must not already exist, as it will be created.

    ogr2ogr -f GPKG filename.gpkg /path/to/dir
Related Question