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

'Control feature rendering order' should have precedence over symbol levels #42428

Open
JohnProv opened this issue Mar 24, 2021 · 4 comments · Fixed by #52096
Open

'Control feature rendering order' should have precedence over symbol levels #42428

JohnProv opened this issue Mar 24, 2021 · 4 comments · Fixed by #52096
Labels
Bug Either a bug report, or a bug fix. Let's hope for the latter! Symbology Related to vector layer symbology or renderers

Comments

@JohnProv
Copy link

Describe the bug
'Control feature rendering order' should have precedence over symbol levels.
Now it isn't possible to create a map with for example correct road outlines and have roads in the correct order (bridge over road etc.).
For a detailed description and examples, see: https://gis.stackexchange.com/questions/204034/can-i-change-the-precedence-when-combining-control-feature-rendering-order-wit

How to Reproduce

  1. Download OpenStreetMap sample data (for example shapefile from http://download.geofabrik.de/)
  2. Open road-layer (shapefile) or open line-layer (Postgis / Osm2pgsql)
  3. Add a rule-based style with an outline
  4. Set symbol levels (0 and 1)
  5. -> Now the map looks correctly (outlines are merged), except bridges over roads (the z-order isn't taken into account)
  6. Check 'Control feature rendering order' and order ascending by 'layer' or 'z_order'
  7. -> The map doesn't change
  8. Delete symbol levels (set all to 0)
  9. -> Map shows bridges correctly, but outlines are not merged at for example intersections.

QGIS and OS versions

QGIS version 3.18.1-Zürich QGIS code branch Release 3.18
Compiled against Qt 5.15.2 Running against Qt 5.15.2
Compiled against GDAL/OGR 3.0.4 Running against GDAL/OGR 3.0.4
Compiled against GEOS 3.8.1-CAPI-1.13.3 Running against GEOS 3.8.1-CAPI-1.13.3
Compiled against SQLite 3.35.2 Running against SQLite 3.35.2
PostgreSQL Client Version 13.2 SpatiaLite Version 4.3.0a
QWT Version 6.1.6 QScintilla2 Version 2.12.1
Compiled against PROJ 6.3.2 Running against PROJ Rel. 6.3.2, May 1st, 2020
OS Version Arch Linux

Additional context
Please let me know if there are other possibilities to achieve the desired effect that I don't know.

@JohnProv JohnProv added the Bug Either a bug report, or a bug fix. Let's hope for the latter! label Mar 24, 2021
@gioman gioman added the Symbology Related to vector layer symbology or renderers label Mar 24, 2021
@Pedro-Murteira
Copy link

This is still valid on QGIS 3.22.3.

joto added a commit to joto/QGIS that referenced this issue Mar 4, 2023
There are two ways of taking "order" into account when rendering:

1. You can control the feature rendering order which essentially does an
   "order by" of your layer data.
2. You can enable symbol levels which defines which styles are rendered
   in which order.

This commit addresses a problem when trying to bring (1) and (2)
together. When both are enabled, the rendering order (2) trumps the
order given by (1), essentially ignoring the order from (1).

With this commit rendering instead starts "from scratch" every time the
"order by" attributes have a new value.

This allows, for instance, to render complex roads networks correctly.
Ordering via (1) is used to draw roads going over bridges etc. in the
correct order while ordering via (2) is used to render road styles
correctly (thicker dark line, then thinner light line to get a roads
with casing).

The patch works by putting all features that need to be rendered not in
a single QHash (Symbol->Feature) but a QList of those hashes. Every time
at least one of the attributes used for the "order by" changes, a new
element is added to that list. The patch is rather simple, it just looks
a bit larger due to the extra indentation needed.

I thought about making this configurable, but I don't see any use case
where it makes sense to have (1) and (2) enabled where you don't want
this behaviour.

Fixes qgis#42428
See qgis#17276
joto added a commit to joto/QGIS that referenced this issue Mar 9, 2023
There are two ways of taking "order" into account when rendering:

1. You can control the feature rendering order which essentially does an
   "order by" of your layer data.
2. You can enable symbol levels which defines which styles are rendered
   in which order.

This commit addresses a problem when trying to bring (1) and (2)
together. When both are enabled, the rendering order (2) trumps the
order given by (1), essentially ignoring the order from (1).

With this commit rendering instead starts "from scratch" every time the
"order by" attributes have a new value.

This allows, for instance, to render complex roads networks correctly.
Ordering via (1) is used to draw roads going over bridges etc. in the
correct order while ordering via (2) is used to render road styles
correctly (thicker dark line, then thinner light line to get a roads
with casing).

The patch works by putting all features that need to be rendered not in
a single QHash (Symbol->Feature) but a QList of those hashes. Every time
at least one of the attributes used for the "order by" changes, a new
element is added to that list. The patch is rather simple, it just looks
a bit larger due to the extra indentation needed.

I thought about making this configurable, but I don't see any use case
where it makes sense to have (1) and (2) enabled where you don't want
this behaviour.

Fixes qgis#42428
See qgis#17276
joto added a commit to joto/QGIS that referenced this issue Mar 13, 2023
There are two ways of taking "order" into account when rendering:

1. You can control the feature rendering order which essentially does an
   "order by" of your layer data.
2. You can enable symbol levels which defines which styles are rendered
   in which order.

This commit addresses a problem when trying to bring (1) and (2)
together. When both are enabled, the rendering order (2) trumps the
order given by (1), essentially ignoring the order from (1).

With this commit rendering instead starts "from scratch" every time the
"order by" attributes have a new value.

This allows, for instance, to render complex roads networks correctly.
Ordering via (1) is used to draw roads going over bridges etc. in the
correct order while ordering via (2) is used to render road styles
correctly (thicker dark line, then thinner light line to get a roads
with casing).

The patch works by putting all features that need to be rendered not in
a single QHash (Symbol->Feature) but a QList of those hashes. Every time
at least one of the attributes used for the "order by" changes, a new
element is added to that list. The patch is rather simple, it just looks
a bit larger due to the extra indentation needed.

I thought about making this configurable, but I don't see any use case
where it makes sense to have (1) and (2) enabled where you don't want
this behaviour.

Fixes qgis#42428
See qgis#17276
joto added a commit to joto/QGIS that referenced this issue Mar 20, 2023
There are two ways of taking "order" into account when rendering:

1. You can control the feature rendering order which essentially does an
   "order by" of your layer data.
2. You can enable symbol levels which defines which styles are rendered
   in which order.

This commit addresses a problem when trying to bring (1) and (2)
together. When both are enabled, the rendering order (2) trumps the
order given by (1), essentially ignoring the order from (1).

With this commit rendering instead starts "from scratch" every time the
"order by" attributes have a new value.

This allows, for instance, to render complex roads networks correctly.
Ordering via (1) is used to draw roads going over bridges etc. in the
correct order while ordering via (2) is used to render road styles
correctly (thicker dark line, then thinner light line to get a roads
with casing).

The patch works by putting all features that need to be rendered not in
a single QHash (Symbol->Feature) but a QList of those hashes. Every time
at least one of the attributes used for the "order by" changes, a new
element is added to that list. The patch is rather simple, it just looks
a bit larger due to the extra indentation needed.

I thought about making this configurable, but I don't see any use case
where it makes sense to have (1) and (2) enabled where you don't want
this behaviour.

Fixes qgis#42428
See qgis#17276
joto added a commit to joto/QGIS that referenced this issue Apr 3, 2023
There are two ways of taking "order" into account when rendering:

1. You can control the feature rendering order which essentially does an
   "order by" of your layer data.
2. You can enable symbol levels which defines which styles are rendered
   in which order.

This commit addresses a problem when trying to bring (1) and (2)
together. When both are enabled, the rendering order (2) trumps the
order given by (1), essentially ignoring the order from (1).

With this commit rendering instead starts "from scratch" every time the
"order by" attributes have a new value.

This allows, for instance, to render complex roads networks correctly.
Ordering via (1) is used to draw roads going over bridges etc. in the
correct order while ordering via (2) is used to render road styles
correctly (thicker dark line, then thinner light line to get a roads
with casing).

The patch works by putting all features that need to be rendered not in
a single QHash (Symbol->Feature) but a QList of those hashes. Every time
at least one of the attributes used for the "order by" changes, a new
element is added to that list. The patch is rather simple, it just looks
a bit larger due to the extra indentation needed.

I thought about making this configurable, but I don't see any use case
where it makes sense to have (1) and (2) enabled where you don't want
this behaviour.

Fixes qgis#42428
See qgis#17276
joto added a commit to joto/QGIS that referenced this issue Apr 23, 2023
There are two ways of taking "order" into account when rendering:

1. You can control the feature rendering order which essentially does an
   "order by" of your layer data.
2. You can enable symbol levels which defines which styles are rendered
   in which order.

This commit addresses a problem when trying to bring (1) and (2)
together. When both are enabled, the rendering order (2) trumps the
order given by (1), essentially ignoring the order from (1).

With this commit rendering instead starts "from scratch" every time the
"order by" attributes have a new value.

This allows, for instance, to render complex roads networks correctly.
Ordering via (1) is used to draw roads going over bridges etc. in the
correct order while ordering via (2) is used to render road styles
correctly (thicker dark line, then thinner light line to get a roads
with casing).

The patch works by putting all features that need to be rendered not in
a single QHash (Symbol->Feature) but a QList of those hashes. Every time
at least one of the attributes used for the "order by" changes, a new
element is added to that list. The patch is rather simple, it just looks
a bit larger due to the extra indentation needed.

I thought about making this configurable, but I don't see any use case
where it makes sense to have (1) and (2) enabled where you don't want
this behaviour.

Fixes qgis#42428
See qgis#17276
@JohnProv
Copy link
Author

JohnProv commented Jul 6, 2023

The problem described in this bug isn't fixed completely with #52096. For the categorized renderer it works well, but not for the rule-based renderer. Please fix that also.
See #52096 (comment)

@m-kuhn m-kuhn reopened this Jul 6, 2023
@JohnProv
Copy link
Author

See the differences between categorised rendering and rule rendering below.

Categorised rendering, this looks good:
Screenshot_20230711_190714

Rule rendering, this doesn't look good:
Screenshot_20230711_190504

(Example: knooppunt Deil, © map data: OpenStreetMap-contributors)

@joto
Copy link
Contributor

joto commented Oct 23, 2023

I had a look at the code to see why this is not working in the rule rendering. The rule based renderer reports that it doesn't support the QgsFeatureRenderer::SymbolLevels capability which makes the rendering take a completely different code path. Obviously it does support symbol levels, but the different code path implements that in a different way. I don't know whether this is just historic and the code could be joined or if there is a reason for the different paths. I'd be happy to work on that some more, but just implementing this feature a second time in the other code paths seems not like a good idea to me.

Maybe somebody with more experience with this code has an idea why these two code paths are there and what to do about it? @m-kuhn

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! Symbology Related to vector layer symbology or renderers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants