TransWikia.com

QGIS 3x - categorized style customization based on a part of the string

Geographic Information Systems Asked on August 24, 2021

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

4 Answers

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

Correct answer by Christophe P. on August 24, 2021

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.

Answered by Cyrmel on August 24, 2021

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

Answered by Nelson Silva on August 24, 2021

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

Answered by JoshC on August 24, 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