5

In QGIS we can package all the layers using the "Package layers" tool but is there a way to also reproject all the component layers within the tool or using ogr2ogr?

We have:

processing.run("native:package", {'LAYERS':['Layer List],
                                  'OUTPUT':'GIS_20210531.gpkg',
                                  'OVERWRITE':False,
                                  'SAVE_STYLES':True})

Can we add something to this code like for /r %f in (*.shp) do ogr2ogr -f "ESRI Shapefile" "%~dpnf_4326.shp" -s_srs EPSG:4283 -t_srs EPSG:4326 "%f" -dsco SHAPE_RESTORE_SHX=YES 1 or the examples in Is there any way to reproject multiple layers in QGIS?

Looking at https://gdal.org/drivers/vector/gpkg.html I can't see any examples for reprojection.

All inputs are vector. I do not want to convert to shp/tab and then reproject and repackage.

Looking for an ogr2ogr or QGIS solution.

1
  • 2
    Try ogr2ogr -f gpkg -t_srs epsg:xxxx new_geopackage.gpkg old_geopackage.gpkg.
    – user30184
    May 31, 2021 at 10:00

1 Answer 1

9

Ogr2ogr can convert with one run all the tables that are given in the command as a list

...input.gpkg layer1 layer2 layer 3

If no layers are given in the command then all layers are processed. Layer is an optional parameter as documented in https://gdal.org/programs/ogr2ogr.html

dst_datasource_name src_datasource_name
  ...    [layer [layer ...]]

If all ogr2ogr parameters are suitable for all the layers (so no renaming of layers etc.) the whole geopackage can be reprojected with one command

ogr2ogr -f gpkg -t_srs epsg:xxxx new_geopackage.gpkg old_geopackage.gpkg
5
  • I do not know really. Why to use QGIS if you can do the task from the command line?
    – user30184
    May 31, 2021 at 13:32
  • 5
    The same result can be achieved in QGIS via Processing Toolbox > GDAL > Vector conversion > Convert format. Choose your GPKG in source, your destination GPKG as output, and in Advanced Parameter type -t_srs epsg:xxxx
    – Taras
    Jun 9, 2021 at 7:17
  • unfortunately the Convert format algorithm does not work on a gpkg with multiple layers, because QGIS creates a wrong ogr2ogr command, here is an example: ogr2ogr -f "GPKG" -t_srs epsg: 32633 C: /Users/pigre/Desktop/sabrina/limiti_admin.gpkg C: /Users/pigre/Desktop/sabrina/limiti_admin.gpkg RipGeo01012021_WGS84
    – pigreco
    Feb 11, 2022 at 17:35
  • github.com/qgis/QGIS/issues/43701
    – pigreco
    Feb 11, 2022 at 18:39
  • 2
    bug fixed in 3.24 : github.com/qgis/QGIS/pull/45955
    – pigreco
    Feb 11, 2022 at 18:53

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.