Bug report #10815

refine rules (add ranges/categories): expressions not applied/written correctly

Added by baditaflorin - over 10 years ago. Updated over 7 years ago.

Status:Closed
Priority:Normal
Assignee:Nyall Dawson
Category:Symbology
Affected QGIS version:master Regression?:No
Operating System: Easy fix?:No
Pull Request or Patch supplied:No Resolution:
Crashes QGIS or corrupts data:No Copied to github as #:19191

Description

new description:

#10815-7


old description:

Expected result . To filter only the numbers on the pntcnt that are higher then 4802

"pntcnt" > 4802

Instead i get only 5 values, from

0-0.2
0.2-0.4
0.4-0.6
0.6-0.8
0.8-1

refine_a_rule_to_ranges_not_working.jpg (31.2 KB) baditaflorin -, 2014-07-05 03:40 AM

strange.jpg (43.4 KB) baditaflorin -, 2014-07-05 04:50 AM

refine_by_categories.jpg (66.8 KB) baditaflorin -, 2014-07-05 05:23 AM

refine_bug.png (47.7 KB) Vladimir Udilov, 2015-09-16 02:30 AM


Related issues

Duplicates QGIS Application - Feature request #10479: Refine current rule Open 2014-06-05

Associated revisions

Revision ae853766
Added by Nyall Dawson about 9 years ago

Fix refining rule based renderer using expression (fix #10815)

History

#1 Updated by Nathan Woodrow over 10 years ago

That isn't doing what you expected it to. What you are doing there is making a range based on the results from the expression "pntcnt" > 4802 which is from 0 -> 1.

What you are looking for isn't implemented yet.

#2 Updated by Nathan Woodrow over 10 years ago

  • Resolution set to duplicate
  • Status changed from Open to Closed

#3 Updated by baditaflorin - over 10 years ago

Yes it is implemented, i discovered it now

CASE WHEN "pntcnt" <50 THEN "pntcnt" END

Thanks for the quick reply

#4 Updated by baditaflorin - over 10 years ago

  • File strange.jpg added
  • Status changed from Closed to Reopened

This is strange, doing a query like this works

CASE WHEN ( "pntcnt" <100.1 ) THEN "pntcnt" END

But searching for bigger numbers not working

CASE WHEN ( "pntcnt" >100.1 ) THEN "pntcnt" END

Or if i search only for 200, i get all the values until 200, as seen in the photo

In this sense you say that is not implemented, that it works only with < ?

#5 Updated by baditaflorin - over 10 years ago

If i choose refine by category, then the CASE ELSE is working, even with

CASE WHEN "pntcnt" >= 50.1000 AND "pntcnt" <= 100.1 THEN "pntcnt" END

As can be seen in the photo

#6 Updated by Jürgen Fischer over 10 years ago

  • Category set to Symbology

#7 Updated by Giovanni Manghi over 10 years ago

  • Status changed from Reopened to Feedback
  • Resolution deleted (duplicate)
  • OS version deleted (7)
  • Operating System deleted (Windows)
  • Subject changed from refine a rule to rules - colums filter not working to refine rules (add ranges/categories): expressions not applied/written correctly

This is what I see (please correct me if I'm wrong):

categorized renderer

  • in the normal categorized renderer I can use an expression like (NUMPOINTS is a integer field)

CASE WHEN "NUMPOINTS" >= 50.0000 AND "NUMPOINTS" <= 100.0 THEN "NUMPOINTS" END

this will effectively create a subset of values and for each of them it will create a separate symbology class

  • in the rule based renderer when I refine a rule (by category), the same expression will result in a filter like (example for just one symbology class)

"CASE WHEN ""NUMPOINTS"" >= 50.0000 AND ""NUMPOINTS"" <= 100.0 THEN ""NUMPOINTS"" END" = 68.0000

and this is wrong, in fact if I remove the not necessary '"' the expression works

CASE WHEN "NUMPOINTS" >= 50.0000 AND "NUMPOINTS" <= 100.0 THEN "NUMPOINTS" END = 68.0000

(and otherwise testing the filter/expression fails with "Column 'CASE WHEN "NUMPOINTS" >= 50.0000 AND "NUMPOINTS" <= 100.0 THEN "NUMPOINTS" END' not found")

  • in a similar fashion an expression like

"NUMPOINTS" > 100

will return 1 or 0 (depending if is true or not that the feature has more than 100 "NUMPOINTS").

This will work ok in the standard categorized renderer but in the rule based one, when refining by category it will result in rules with too many '"', example

"CASE WHEN ""NUMPOINTS"" >= 50.0000 AND ""NUMPOINTS"" <= 100.0 THEN ""NUMPOINTS"" END" = 59.0000

Similar observations can be done for graduated renderer:

  • in the standard graduated renderer an expression like

CASE WHEN "NUMPOINTS" >= 50.0000 AND "NUMPOINTS" <= 100.0 THEN "NUMPOINTS" END

can be used to effectively render (by ranges) only the features with "NUMPOINTS" between 50 and 100

  • when the same expression is used to refine a rule based rule by adding a range then is written wrong (example, for one symbology class):

"CASE WHEN ""NUMPOINTS"" >= 50.0000 AND ""NUMPOINTS"" <= 100.0 THEN ""NUMPOINTS"" END" >= 84.0000 AND "CASE WHEN ""NUMPOINTS"" >= 50.0000 AND ""NUMPOINTS"" <= 100.0 THEN ""NUMPOINTS"" END" <= 97.0000

  • similar observation for an expression like

"NUMPOINTS" > 100

This does not seems to work on 2.2 either, where the expressions were introduced to allow more advanced categorized/graduated symbology, then it should be tagged as blocker, because is a new feature that does not work as expected (at least inside the rule based symbology).

#8 Updated by Giovanni Manghi over 9 years ago

  • Affected QGIS version changed from 2.4.0 to master
  • Status changed from Feedback to Open

#9 Updated by Vladimir Udilov over 9 years ago

I can reproduce this bug in 2.10.1.
Basically when you refine a rule (adding range or category both) using an expression instead of just a field, left parts of sub-rules that are created are escaped as if they were a field name. See attached screenshot - double quotes inside expression and unneeded quotes around expression can be seen.
Escaping was probably added when fixing this bug: Issue #5536

#10 Updated by Nyall Dawson about 9 years ago

Some more detail in #13561

#11 Updated by Nyall Dawson about 9 years ago

  • Assignee set to Nyall Dawson

#12 Updated by Nyall Dawson about 9 years ago

  • Status changed from Open to Closed

#13 Updated by Jürgen Fischer over 7 years ago

  • Description updated (diff)

Also available in: Atom PDF