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.

  • 1
    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 '17 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 '17 at 13:28
  • 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 '17 at 13:56

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.