I use QGIS 3.2 to select features in a shapefile. Lets say I have shapefile which contain 100 features and have such fields:
Classwith possible valuesA,B,C.IDwith possible integer values0, 1, 2, 3, ... , 99.
How to select exactly one feature (no matter which one) in every class A,B,C?
Answer
Using the Select by Expression you can type the following expression:
"Class" IN ('C', 'B') AND
"ID" = minimum( "ID", "Class")
This expression will select the feature with Class = B, C with the lowest ID, assuming the ID is a unique value.
If the ID is not a unique value, using the field calculator you can create a new integer column, name it ser_id or something along the line and assign to it the value $id. This is the row number and it is a unique value.

No comments:
Post a Comment