6

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

2

2 Answers 2

7

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

enter image description here

  • 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'

enter image description here

  • Go to the Layer properties of the vector layer -> Fields, and change the Edit widget from Text Edit to Value Relation

enter image description here

  • 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.

enter image description here

Here is the output:

enter image description here

2

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.

enter image description here

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:

enter image description here

QGIS 2.18 Layer Properties dialog- Fields tab:

enter image description here

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.

enter image description here

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.

enter image description here

On saving the newly created feature, the taxon name values are written back to the attribute table.

enter image description here

3
  • 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
    Dec 26, 2018 at 8:42
  • Sorry press post by mistake.
    – Plecotus
    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
    Dec 26, 2018 at 8:45

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.