TransWikia.com

QGIS make the appearance of selected feature the same as defined in symbology

Geographic Information Systems Asked on April 4, 2021

I want to select my item one by one in order to capture them separately.
I defined their colour like blue and thickness as 1.

According the thread below:

Displaying only selected features on map in QGIS?

I could smoothly define the rule and show only selected elements on my map.
However, they appear still as per the default selection settings set in the QGIS options…

enter image description here

I can admittedly change them easily by following the thread here:

Is there anyway to modify thickness & color of a selected polygon?

QGIS 2.8 Change Colour of Selected features

but the problem is, that it’s going to be applied for all other items/layers concerned in my project, or even the entire QGIS program.

I would like to keep this changed option only for the layer I am working on right now. Is it possible to change the selection options individually for the layer concerned, or shall I go with the general options as discussed in the threads above?

One Answer

You can create a virtual layer that will display the selected feature.
This virtual layer should be located above the main layer.

  1. Add a virtual field to the point layer, of type integer size 1 and populate it using the expression is_selected()

(note: don't use a boolean type because of this bug.)

`enter image description here

So when a line is selected, the value in this field will be set to 1.

  1. Create a virtual layer that will display only the selected line.

Go to the menu Layer > Add Layer > Add/Edit Virtual Layer... and enter the following query. Replace the layer name for yours

select l.*
from lines l 
where  l.selected = 1
  1. Style this virtual layer as you wish.

When you select a line, you will have to pan the map a bit to refresh the virtual layer.

  1. If you want, you can hide the original selection. In the main layer, in the rule-based symbology, un-tick the box beside the "selected" rule. Doing so will let you apply a thin line style on the selected line.

Correct answer by JGH on April 4, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP