Is it possible to create a multiple select dropdown list/select widget in QGIS which links to a separate txt file?
I want to collect species lists for different locations in QField but do not want to have to enter hundreds of species names manually.
I am using QGIS 2.18
-
This tutorial should have what you're after: northrivergeographic.com/archives/qgis-and-value-mapsInactivated Account– Inactivated Account2018年12月23日 17:26:46 +00:00Commented Dec 23, 2018 at 17:26
-
This post might assist you: gis.stackexchange.com/questions/239348/…. I had the same issue recently. QField doesn't support csv or txt files, but you can have your value relation table in a format that it supports such as shp or postgis. Works well for me with multiple check boxes.Ville Koivisto– Ville Koivisto2020年03月12日 08:43:50 +00:00Commented Mar 12, 2020 at 8:43
2 Answers 2
First I recommend to use QGIS 3.4.2, because QGIS 2.18.26 did not provide the desired results.
If your species data are saved in a CSV file, load the data into the QGIS as a table from Add vector layer NOT from Add delimited text layer along with the vector layer that you want to populate its field with the species information as follows:
- Use Add vector layer to load both the vector file and the CSV file
- Start Editing of the vector file -> Add a new field in the attribute table of type
Text
to populate it with information from the CSV file'
- Go to the
Layer properties of the vector layer -> Fields
, and change theEdit widget
fromText Edit
toValue Relation
Under Select Layer, Key Column, Value Column, select the CSv file that contains the species information, use ID column as Key Column, and Species Name as Value Column as shown below, and click OK.
Now Go to to the attribute Table of the vector layer -> Species Column -> You will see a drop down list coming from the CSV file in which you can choose the species names.
Here is the output:
Firstly, if you want to use this for data collection with QField, then I don't think solutions using the 'Value Relation' edit widget will work, because at present (Dec 2018) the value relation widget type does not seem to be supported in QField. However, according to the QField documentation, the 'Value Map' edit widget is supported:
https://www.qfield.org/docs/project-management/vector-layers.html
So I recommend to use the value map edit widget in your layer properties. I have tested the project settings in both QGIS 2.18 and 3.4, and theoretically, this should work when you export your project to QField (I have not tested that part though).
I created a spreadsheet like below and saved as a csv.
I loaded the csv via Add Delimited Text Layer, and specified 'No Geometry'. I also have a point vector layer called 'Field_data'. This layer has a field called 'Taxon name' which I want to edit with a drop down list of multiple species. I open the layer properties dialog for this layer and change the edit widget for the 'Taxon name' field from Text Edit to Value Map. The layer properties dialogs are slightly different for 3.4 and 2.18 (see images below).
QGIS 3.4 Layer Properties dialog- Attributes Form tab:
QGIS 2.18 Layer Properties dialog- Fields tab:
Next, I click 'Load Data from Layer' and select the Species_list csv as the layer and select the 'value' and 'description' columns from the csv layer.
Now when I add a new feature to my Field_data layer, the values for the 'Taxon name' field come from a combo box populated with the species names from my csv file.
On saving the newly created feature, the taxon name values are written back to the attribute table.
-
I have no experience with using the widgets in QGIS or Qfield. Likewise i have not used database relation options available so i am not entirely clear.Plecotus– Plecotus2018年12月26日 08:42:16 +00:00Commented Dec 26, 2018 at 8:42
-
Sorry press post by mistake.Plecotus– Plecotus2018年12月26日 08:42:54 +00:00Commented Dec 26, 2018 at 8:42
-
Will the above allow me to add multiple species (plant) to each polygon in the vector layer? I.e. by using primary and secondary key like in #ahma previous post?Plecotus– Plecotus2018年12月26日 08:45:27 +00:00Commented Dec 26, 2018 at 8:45
Explore related questions
See similar questions with these tags.