Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show Feature Count shows wrong numbers with rule-based classification when rules were copied/pasted via the contextmenu #40206

Open
pathmapper opened this issue Nov 20, 2020 · 11 comments
Labels
Bug Either a bug report, or a bug fix. Let's hope for the latter! Map and Legend Related to map or legend rendering

Comments

@pathmapper
Copy link
Contributor

pathmapper commented Nov 20, 2020

Describe the bug

Show Feature Count shows wrong numbers with rule-based classification when rules were copied/pasted via the contextmenu.

How to Reproduce

Data used in the test cases of this ticket is from
WFS: https://geoservices.krzn.de/security-proxy/services/wfs_verb_grenzen
Layer: gis:gemeindegrenzen

  1. Add the WFS layer mentioned above to the legend.
  2. Add rule-based classification with copied/pasted rules like shown in Show Feature Count shows wrong numbers with rule-based classification when rules were copied/pasted via the contextmenu #40206 (comment) . The result will be the same as in this sample_layer_definition_file.zip.
  3. Open contextmenu of the layer and click on Show Feature Count.
  4. See error: Feature Count for Viersen, Krefeld and Wesel is wrong, e.g. click on "Test" in the "Edit Rule" window, compare with attribute table or visually count the features on the canvas.

grafik

QGIS and OS versions

QGIS version 3.16.0-Hannover QGIS code revision 43b64b1
Compiled against Qt 5.11.3 Running against Qt 5.11.3
Compiled against GDAL/OGR 2.4.0 Running against GDAL/OGR 2.4.0
Compiled against GEOS 3.7.1-CAPI-1.11.1 Running against GEOS 3.7.1-CAPI-1.11.1 27a5e771
Compiled against SQLite 3.27.2 Running against SQLite 3.27.2
PostgreSQL Client Version 11.9 (Debian 11.9-0+deb10u1) SpatiaLite Version 4.3.0a
QWT Version 6.1.4 QScintilla2 Version 2.10.4
Compiled against PROJ 5.2.0 Running against PROJ Rel. 5.2.0, September 15th, 2018
OS Version Debian GNU/Linux 10 (buster)
Active python plugins ClipMultipleLayers; quick_map_services; scriptrunner3; LAStools; canvas_clipper; savedialog; loadthemall; clipper; kmltools; qgis-maptiler-plugin; MapsPrinter; Discovery; mmqgis; pluginbuilder3; vector_tiles_reader; layerGroupFilter; plugin_reloader; realcentroid; mask; MetaSearch; db_manager; processing

Additional context

The similiar issue #39318 was closed because it was not reproducible.

There's something wrong in general with Show feature count for rule-based classification: #27893, #27892

@pathmapper pathmapper added the Bug Either a bug report, or a bug fix. Let's hope for the latter! label Nov 20, 2020
@gioman gioman added the Feedback Waiting on the submitter for answers label Nov 20, 2020
@gioman
Copy link
Contributor

gioman commented Nov 20, 2020

@pathmapper same as #37799 ?

@roya0045
Copy link
Contributor

@gioman I'd say yes.

@pathmapper
Copy link
Contributor Author

same as #37799 ?

@gioman I'd say no, because if I understood it correct #37799 is not about showing wrong numbers, instead it's about showing the total number of features even if a filter is applied. I'd say that #37799 is a duplicate of this feature request: #29458

The issue reported in this ticket here is about showing wrong numbers. The count number 23 shown is totally wrong and has nothing to do with the total number of features. 23 is the total number of features minus all features which are not "KREIS" = 'Kleve'.

Correct would be:

Kreis feature count
Viersen 9
Krefeld 1
Wesel 13
Kleve 16
total 39

@roya0045
Copy link
Contributor

Did you toggle the count when you had only two classes? This would indicate so.

@pathmapper
Copy link
Contributor Author

Did you toggle the count when you had only two classes?

@roya0045 no, just reproduced the issue:

wrong_feature_count

@roya0045
Copy link
Contributor

What if you use the category symbology first to get the classes and then switch to rule-based? Or used the refine selected rules button instead of doing it all one by one?

@pathmapper
Copy link
Contributor Author

What if you use the category symbology first to get the classes and then switch to rule-based?

In this case the numbers are correct:
use_category_first

Or used the refine selected rules button instead of doing it all one by one?

If you mean something like the following, it works also:

refine_selected_rules

Here is another one using the Add Rule button:

Use_plus_button


So it looks like the bug here which leads to wrong feature count numbers is regarding the use of copy/paste of rules via the contextmenu:

@pathmapper pathmapper changed the title Show Feature Count shows wrong numbers with rule-based classification Show Feature Count shows wrong numbers with rule-based classification when rules were copied/pasted via the contextmenu Nov 21, 2020
@roya0045
Copy link
Contributor

Ok I think this is enough to isolate the issue.

When counting features the rulekeys for feature is used

const QSet<QString> featureKeyList = mRenderer->legendKeysForFeature( f, renderContext );

In the rule based render the keys are generated at the start
mRuleKey = QUuid::createUuid().toString();

But to maintain some usability those keys are not changed when cloning.

// normally with clone() the individual rules get new keys (UUID), but here we want to keep

@nyalldawson would it be a good idea to use the filter expression as a key? I know that this can be more complex with nested symbols as there can be duplicates in different branches. But my older PR has code to get a full comprehensive expression string for each 'node', this would solve that issue.

@gioman gioman removed the Feedback Waiting on the submitter for answers label Dec 6, 2020
@gioman gioman added the Map and Legend Related to map or legend rendering label Jan 3, 2021
@beerockxs
Copy link

Using 3.22-1, I have this issue without having copy-pasted rules. I created a rule based symbology and refined it for two additional levels using the "Refine Selected Rules" button and adding further categories:

grafik

@pathmapper
Copy link
Contributor Author

But to maintain some usability those keys are not changed when cloning.

Yep, if the style is exported as .qml, the first three rules are having the same key.

grafik

If you manually edit the .qml so that the keys are unique, the style works as expected.

@lp-dj
Copy link

lp-dj commented Sep 13, 2022

I would like to add that I sometimes have the problem with single symbol styling as well:

grafik

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Either a bug report, or a bug fix. Let's hope for the latter! Map and Legend Related to map or legend rendering
Projects
None yet
Development

No branches or pull requests

5 participants