I am setting up a QGIS project using a Geopackage (or shapefile) concerning the areas named with some historical toponyms and writing a brief description of them.
In the attribute table I would like to include a field in the form of "tags" (such as Youtube videos or this forum), where I can insert more keywords referenced in a single field to assign a "kind" to the object and facilitate the management of data.
The question is that an element in my conceptual model can have more genres.
For example, an element can have keywords at the same time: "restaurant", "hotel", "garden".
In a field in the attribute table I am allowed to insert only one of these values.
How could I enter multiple values in a field as an alternative to a static text system "restaurant, hotel, garden"?
Best Answer
Use the "Value Relation" field widget to select multiple items from a list
1. Create a spreadsheet with two columns.
Call the first column "key." In this column, enter the values that you want saved in the attribute table. You can use your keywords, or you can assign a shorter key to each keyword. For example, I used numbers as my keys. The value "hotel" will be saved in the attribute table as 1. This allows you to store relatively long values in a more compact format. You could also use abbreviations, such as h for hotel, and g for garden. If you prefer, you can put the same value in each column.
Call the second column "value." In this column, put all of your keywords ("restaurant", "hotel", "garden" and so on).
Save the spreadsheet in csv format.
2. Import the csv as an attribute-only table (ie without geometry).
3. Set up value relation widget
Open layer properties for the historical areas layer. Open the Attributes Form tab. Select the field (in my example the field is "categories"). For Widget Type, choose "value relation." For layer, select the table you added in step 2. (in my example the table is called "book2"). For key, select the key column. For value, select the value column.
When you create a new point, the data entry form will now give you a checklist.
The attribute table will store multiple values in a single field: