6

I have successfully saved several layers in one GeoPackage in QGIS 3.8. This is how it looks like in DB manager:

QGIS DB managere

I found out that the ordering of the layers is somehow strange when loading the GPKG file in QGIS:

GPKG after loading

Of course, I can manually change the layer ordering by dragging them in the Layers panel up or down but it would be nice if the default order could be correct by default. Same with the layer names in QGIS - is there any way to exclude the filename from the layer name?

That means get the layers loaded this way by default?

enter image description here

Because the support for multiple layers in one GeoPackage file is the much less useful if I have to manually adjust the names and ordering each time.

I tried to import the layers from my GPKG to another one but the resulting order was the same... Is there any way to solve this?

1
  • 1
    The ordering is alphabetical, so this is rather you having a special idea of how it should be? You could load the geopackage twice, once only the cities & borders, without a folder, then the Fukushima-layer inside a folder. You can toggle this while loading files which contain several layers.
    – Erik
    Commented Oct 17, 2019 at 6:37

3 Answers 3

3

Renaming and giving each layer a numerical prefix, as others suggested, should do the job as the layers in the geopackage are simply loaded in their alphabetical order.

to rename all of them after beeing loaded (and remove the geopackage's name as prefix, you can create & run a small pyhton script in the console:

from qgis.utils import iface
from qgis.core import QgsExpressionContextUtils

layerList = QgsProject.instance().layerTreeRoot().findLayers()
for layer in layerList:
   basename = layer.name()
   layer.setName(basename.replace("your_prefix_you_want_to_remove ",""))

Alternatively, do not drop the whole geopackage into your project, rather select all layers in your geopackage and drag & drop them into the project - they will be added without the package's name as prefix:

enter image description here

2

You can rename the layers of your GeoPackage in the DB Manager with an alphabetical or numerical prefix to change the order of your layers. For example:

'NPP Fukushima1 point' > '1 - NPP Fukishima1'

'NPP Fukushima1 20km zone' > '2 - NPP Fukishima1 20km zone'

1

I encountered the same wrong layer order problem using QGIS 3.4. The "rename the layers" workaround worked for me.

Just be aware that some associations may be broken when you rename the layer, so you may need to re-create these associations. In my case, the default styles (from the database) that I had set before renaming the layers were no longer being used as the defaults after the name changes.

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.