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.

Taras
  • 32,823
  • 4
  • 66
  • 137
GeorgeC
  • 8,228
  • 7
  • 52
  • 136

1 Answers1

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
user30184
  • 65,331
  • 4
  • 65
  • 118
  • I do not know really. Why to use QGIS if you can do the task from the command line? – user30184 May 31 '21 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 09 '21 at 07: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 '22 at 17:35
  • https://github.com/qgis/QGIS/issues/43701 – pigreco Feb 11 '22 at 18:39
  • 2
    bug fixed in 3.24 : https://github.com/qgis/QGIS/pull/45955 – pigreco Feb 11 '22 at 18:53