5

I have a problem. I am digitizing the map and I want to distinguish one group of polygons from the other group. The basic difference between them lies in their ID (string). One of them has the ID starting from SE-1-... and the other ones start from SE-2-...

I found some hints here:

How to select features containing specific text string using an expression in QGIS

which unfortunately doesn't work in my example. Once I write down the function, next press the "Add" (plus) button I am getting the box allocated for "All other values". enter image description here

Is there any way to separate these 2 groups by this part of the string? Categorizing by ID doesn't make sense, because all polygon get their unique color, which makes a terrible mess.

UPDATE:

Function is not valid, the details are in the box below:

enter image description here

3

You did not specify the value which triggers whether your polygon should go into the first group or not - "TITLE" LIKE %SE-2% returns 1 for true and 0 for false. instead of "all other Values", set one colour to 1 and one to 0.

1
  • So what formula you suggest?
    – MKR
    Jul 20 '20 at 11:44
3
+50

In addition to Cyrmel: The formula is "TITLE" LIKE '%SE-2%' and than you have to classify (to 1/0 or true/false). If you want, you can also change manually the 0 and 1 in the legend.

enter image description here

3

Assuming Consistent Formatting in TITLE Field

The expression substr("TITLE", 4, 1) returns the fourth character of the string. If the TITLE field is consistently formatted, this will correspond to the particular category, either 1 or 2. Just enter that expression and click classify.

categorize on substring

Alternatively, you could modify substr's starting position and length, or if the SE-# is always at the beginning, simply use left("TITLE", 4) to get the SE-# text, not just the number.

categorize on longer substring

Inconsistent Formatting in TITLE Field

If the SE-# text does not consistently appear at the beginning of the string, you can use the regex_substr function. This is easiest for grabbing the entire SE-# text, but can be modified to grab just the number, or you can nest it within a right function instead.

regexp_substr("TITLE", 'SE-[1,2]')

regex substring

0

Have you tried Conditional expressions like IF or CASE? Something like if( "TITLE" = 'SE-1' , 1, 0 )

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.