I'm trying to make a species distribution project where I can select a species from a non-spatial list of species and the selection would highlight (select) all the counties to which the species has been attributed.

Simplified example data:
species, a non-spatial table of species (CSV with header):
"Mus borealis"
"Mus australis"

species_distributions, a non-spatial relation table (csv with header):
"Mus borealis","North"
"Mus borealis","Central"
"Mus australis","South"
"Mus australis","Central"

counties, a spatial feature class representing county boundaries (first row = field name):

So if I select "Mus borealis" from the species table, the "North" and "Central" counties would be highlighted in the map. Seems like a simple scenario, but I have been unable to uncover a solution on my own. The closest I've found is a plugin "Select by relationship" but it doesn't appear to be available for QGIS 3 (I'm using QGIS 3.4.3). I have a PostGIS server available.

1 Answer 1


First option is:

First open Plugins | Settings and enable Show also experimental plugins

enter image description here

Now you can install Select by relationship plugin

enter image description here

Now set up two relations in Project --> Properties --> Relations

First is:

  • Name: sc (or whatever)
  • Referenced Layer: species_distributions
  • Referenced Field: county
  • Referencing Layer: speciescounty
  • Referencing Field: county
  • Id: sc (or whatever)
  • Strength: Association

Second is:

  • Name: sd (or whatever)
  • Referenced Layer: species
  • Referenced Field: species
  • Referencing Layer: species_distributions
  • Referencing Field: species
  • Id: sd (or whatever)
  • Strength: Association

enter image description here

Now activate the plugin and the relations.

enter image description here

When you now open the attribute table of species layer and select your species, the countys will be highlighted.

enter image description here

enter image description here

enter image description here

For my example I used exactly your species, counties and stuff. The one in the middle is "Central" and so on...

Second option is:

Use only species_distibutions table and county file. And select the species inside species_distributions. Add a rule based renderer to county file with the following rule is_selected( 'species_distributions', get_feature( 'species_distributions', 'county', "county")) and a second one with ELSE. When you now select the species/counties in species_distributions the counties will get a different style. This option was inspired by another great question/answer yesterday here: QGIS3: displaying (or filtering) features in one layer based on features selected in another. I bet there must be some way to also include species table and make your selection in there, but so far I could not make it work.. will update if I find a way.

  • First option works like a charm. You wouldn't believe how long I've been fiddling with this. I'll try the second option once I get over the euphoria.
    – Lee
    Commented Jan 20, 2019 at 1:11

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.