CaptainDang / save_all

3 stars 1 forks source link

Need to append `|layername=...` to vector layer source #9

Open AlisterH opened 2 months ago

AlisterH commented 2 months ago

When you create multi-layer geopackages (e.g. to write layer styles into them) I think you need to load them into QGIS differently. This plugin loads vector layers so that Layer Properties>Information>General shows like this:

Name
Vectorized1
Path
C:\Users\alister\Desktop\saveall test\Vectorized1.gpkg
Size
14.41 MB
Last modified
Friday, 12 April 2024 9:18:16 PM
Provider
ogr

If you try to use the layer as an input for a grass processing algorithm it will produce an error like this: ERROR: Detected different projections of input layers. Input layers must be imported separately. This message is a bit misleading, because there is only one geospatial layer in the gpkg, but there is a layer_styles table. This error is of course followed by errors like this: ERROR: Vector map <vector_6615d74c21edd12> not found If the same gpkg is loaded into QGIS by drag and drop Layer Properties>Information>General shows like this:

Name
Vectorized1
Path
C:\Users\alister\Desktop\saveall test\Vectorized1.gpkg
Size
14.41 MB
Last modified
Friday, 12 April 2024 9:18:16 PM
Source
C:/Users/alister/Desktop/saveall test/Vectorized1.gpkg|layername=Vectorized1
Provider
ogr

This is what gdal says about the file:

#  ogrinfo *.gpkg
INFO: Open of `Vectorized1.gpkg'
      using driver `GPKG' successful.
1: Vectorized1 (Polygon)
2: layer_styles (None)

When QGIS processing creates a vector layer QGIS loads it without that |layername=..., and it doesn't cause a problem, but that is because it doesn't have layer styles saved in the gpkg, so gdal just lists the Polygon layer, like this:

 ogrinfo *
INFO: Open of `output.gpkg'
      using driver `GPKG' successful.
1: output66c870d97a1243c2ac78d634bbb37876 (Polygon)

If this plugin is going to save a gpkg with a layer_styles table then it also needs to append |layername=... to the layer source when loading it into the project.

AlisterH commented 2 months ago

Of course an easy workaround for those who don't need the styles packaged is to change this code: 'SAVE_STYLES': True to this: 'SAVE_STYLES': False