2

I'm using ogr2ogr in a bash script to merge multiple gpkg files. What I'm doing basically looks like this:

ogr2ogr -f 'gpkg' -append merged.gpkg input_file_1.gpkg
ogr2ogr -f 'gpkg' -append merged.gpkg input_file_2.gpkg
ogr2ogr -f 'gpkg' -append merged.gpkg input_file_3.gpkg

So all the input_file_x.gpkg end up in merged.gpkg. This works fine, except a new vector layer is created for every input file, which I want to avoid. As far as I understand it, the -append flag should take care of this.

From man ogr2ogr:

-append: Append to existing layer instead of creating new

All of the input files look identical in terms of attributes and geometry type.

3
  • 2
    From man ogr2ogr: -nln name: Assign an alternate name to the new layer. If you have layer "foo" in the GeoPackage you can add data into that by using -append -nln foo.
    – user30184
    Jun 16, 2017 at 14:35
  • Thanks for the hint, I managed to merge my files. Although this seems like a bit of a hack to me. I wonder if there's a proper solution to this.
    – karpfen
    Jun 18, 2017 at 13:28
  • 1
    That's how ogr2ogr is made to work. It might be possible to get the same result with ogrinfo and -SQL parameter by running something like INSERT INTO my_table VALUES ( ... but using ogr2ogr with -append and giving the name of the table where to append with -nln is the common way.
    – user30184
    Jun 18, 2017 at 13:56

2 Answers 2

1

Have you tried ogrmerge.py, which is available since GDAL/OGR 2.2.0 ? You can run:

ogrmerge.py -f GPKG -o merged.gpkg *.gpkg
0

As already commented you should specify the layer name with -nln to make sure all geopackages are written to this layer.

ogr2ogr -f 'gpkg' -append -nln layer123 merged.gpkg input_file_1.gpkg
ogr2ogr -f 'gpkg' -append -nln layer123 merged.gpkg input_file_2.gpkg
ogr2ogr -f 'gpkg' -append -nln layer123 merged.gpkg input_file_3.gpkg

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.