4

I would like to save my file as the .geopackage file. Unfortunately, I've noticed that the order of the layers is not correct. It doesn't correspond to the order in the "Layers" panel.

I saw, that the DB manager is required for this purpose:

https://www.reddit.com/r/QGIS/comments/l5r2pa/grouping_layers_inside_geopackage/

or some coding is required:

Reordering layers in GeoPackage and changing the default naming in QGIS?

enter image description here

but is there some other option, which would assure me, that the layers in .geopackage file are in the correct order? It applies also to the situation after saving. When I attended to load the .gpkg file, this order is also different. How can I solve this problem?

15
  • 2
    There is no inherent order to tables in a geopackage (or other database)
    – Ian Turton
    Mar 15, 2022 at 13:03
  • 1
    QGIS obviously sorts the tables by default in alphabetical order but you can order the layers as you wish and save the QGIS project. When you re-open the project the layers should appear in the same order.
    – user30184
    Mar 15, 2022 at 13:11
  • 3
    For clarification, the layer order is preserved in the layer list of the QGIS project (TOC). In datastore view they are in alphabetical order. That is IMHO alto the right and logical way to present the database layers. I am not sure which layer order is important for you. It feels odd if the order in the layer list is not preserved in the project file with QGIS 3.12 because it would affect also rendering - roads could be buried under land usage layers etc.
    – user30184
    Mar 15, 2022 at 17:04
  • 1
    I think you can store a project into a geopackage. It's under File->Save to->GeoPackage... ocw.un-ihe.org/mod/book/view.php?id=6859&chapterid=642 As some comments said: the order of QGIS-Layers is defined in the project. A GPKG-Layer is not the same as the QGIS-Layer. Mar 18, 2022 at 18:18
  • 1
    This is a hacky workaround, but what if you just add a numerical prefix (i.e., 1-, 2-, 3-, etc..) in front of all your layer names that reflects the order you want them saved in? Since they are being alphabetized on save, that should give you the result you want.
    – Kartograaf
    Mar 21, 2022 at 22:01

1 Answer 1

4
+50

Because (in earlier releases of QGIS) the layers in your project are being reordered alphabetically on save to geopackage, there is no built in way to preserve the layer order and override this alphabetization in this case.

However, one workaround is to simply add an alphabetical or numerical prefix at the front of your layer names that reflects the order you would like them to be saved in (i.e., A-, B-, C-, etc... or 1-, 2-, 3-, etc...) and let the new names dictate the way they will be reordered in the geopackage.

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.