5

I would like to connect my taxon name column (value map) with a new column (scientific name). How to make a new scientific name autofilled when I choose a taxone name from the list?

For example: I'm choosing name from the list in the column "taxon name": Black woodpecker, and I'd like to my second column autofilled with the right scientific name: Dryocopus martius. I have both lists with names and scientific names in csv.

Paula
  • 51
  • 1

1 Answers1

6

Let's assume there is polygon layer called 'test2' with several features in it, see image below.

input

Step 1. Create a drop down list with values for the "TaxonName" field. Check these threads for more details: Creating drop down list with values in QGIS and Creating multiple select dropdown list in QGIS

step1

Step 2. Generate manually/programmatically a map object from your CSV or list with taxon and scientific names accordingly, e.g. map(key1,value1,key2,value2…).

map('Black woodpecker','Dryocopus martius 1','Red woodpecker','Dryocopus martius 2','White woodpecker','Dryocopus martius 3')

sorry if this example is meaningless in terms of zoology

If you prefer to work with a CSV that contains taxons, then simply drag&drop it into QGIS, see image below.

csv

Step 3. Change the default value for "Scientific" field via Layer Properties > Attributes Form > Fields > [Field] > Defaults

step3

using this expression that will contain that map object:

if("TaxonName", map_get(map('Black woodpecker','Dryocopus martius 1','Red woodpecker','Dryocopus martius 2','White woodpecker','Dryocopus martius 3'), "TaxonName"), NULL)

or another expression if referring to a CSV:

if("TaxonName", attribute(get_feature('birds', 'TaxonName', "TaxonName"), 'Scientific'), NULL)

and click Apply.

Then you achieve the desired output in the "Scientific" field after selecting the "TaxonName":

result

Taras
  • 32,823
  • 4
  • 66
  • 137