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):
"species"
"Mus borealis"
"Mus australis"
species_distributions, a non-spatial relation table (csv with header):
"species","county"
"Mus borealis","North"
"Mus borealis","Central"
"Mus australis","South"
"Mus australis","Central"
counties, a spatial feature class representing county boundaries (first row = field name):
"county"
"North"
"South"
"Central"
"West"
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.
Best Answer
First option is:
First open
Plugins | Settings
and enableShow also experimental plugins
Now you can install
Select by relationship
pluginNow set up two relations in
Project --> Properties --> Relations
First is:
Second is:
Now activate the plugin and the relations.
When you now open the attribute table of
species
layer and select your species, the countys will be highlighted.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 andcounty
file. And select the species insidespecies_distributions
. Add a rule based renderer tocounty
file with the following ruleis_selected( 'species_distributions', get_feature( 'species_distributions', 'county', "county"))
and a second one withELSE
. When you now select thespecies/counties
inspecies_distributions
thecounties
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 includespecies
table and make your selection in there, but so far I could not make it work.. will update if I find a way.