1

Is there a possibility to change the Domain Field Values after saved in the QGIS geopackage?

Here I have e.g. a geopackage and set up a new domain rightclick .gpkg in Browser -> New Domain: enter image description here

How can I add e.g. Type 4 to the Values after saving the domain?

1
  • So long story short: There is no built-in QGIS editor that lets you edit the domain after saving it. Thats a bit odd. Thank you anyway. I will try the SQL-Part when I are more experienced :) @J.R Nov 10, 2023 at 15:04

1 Answer 1

2

It's possible to modify the domain after creation but it's not straightforward, in your exemple it will probably be simpler to just delete the domain and recreate it. That being said, to modify a GPKG domain you need to modify the table that store the domain information, to do that :

  • Make a copy of your GPKG as a backup if something go wrong

  • in QGIS open the DB manager (in the menu : Database > DB manager or add the database toolbar and click on the database icon)

  • In the provider panel of the BD manager right click on SpatiaLite and choose "New connection..." then navigate to your geopackage and select it. You want to add a SpatiaLite connection rather than the more logical GeoPackage connection to be able to look at system table. The procedure will work the same if you add a GeoPackage connection, you just wont be able to check table or field name or to see what your domain currently look like.

  • Select the connection corresponding to your geopackage and open the SQL window (menu : Database > SQL Window or click on the wrench icon)

  • To add a new domain value (in your exemple 'Type 4') enter the following SQL and click the Execute button

    INSERT INTO "gpkg_data_column_constraints" (constraint_name, constraint_type, value, description) values ('Type', 'enum', 'Type 4', 'Type 4');

or in a more general way

INSERT INTO "gpkg_data_column_constraints" (constraint_name, constraint_type, value, description)
VALUES ('Domain name', 'enum', 'Domain code', 'Domain description');
2
  • Thank you for your fast response @J.R . That makes sense. So we change with SQL the intern table for the domain programmically. So in theory QGIS could implement this if they would create sort of a Qt Button and connect it the code you provided. So this would be user friendly :) Nov 11, 2023 at 9:38

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.