[GIS] QGIS 3.0 point cluster renderer, is it possible to control rendering order (z-order)

clusteringqgisqgis-3rendering

I've been having a play with the new point cluster renderer in QGIS 3.0.2 and it's great – a lot easier (and faster) than having to do the clustering yourself.

To show what I mean, here's an example of road accidents in Edinburgh using STATS19 data and a 30m radius.

enter image description here

I can't work out how to set up the z-order so that the largest clusters are drawn in front of smaller clusters.

I'm aware of the @cluster_size variable – it's what I'm using to scale and colour the symbols. For this I'm using the size and colour assistants. I removed the font markers to remove the text from each cluster.

Size of markers is defined as follows:-

coalesce(scale_exp(@cluster_size, 0, 50, 1, 200, 0.57), 0)

Colour of markers is defined as follows:-

coalesce(ramp_color('custom ramp',scale_linear( @cluster_size, 0, 50, 0, 1), '#000000')

What I've tried so far:-

  • Symbol Levels – No luck; unable to select a variable name.
  • Layer rendering > Control Feature Rendering Order and choose @cluster_size as sort. Doesn't appear to have an effect.
  • Graduated style using @cluster_size as the expression doesn't work.

Does anyone know if this is possible, or is this a limitation with this particular renderer?

I know there's a lot of other ways to do this (buffer/spatial join, plugins), but the new renderer should be a lot faster. Or have I overlooked something obvious? 🙂

Best Answer

It seems as though the point cluster implementation does not allow for this natively.

Consider the point cluster renderer - it essentially analyzes and clusters point data at render time, creating a new pseudo layer. This layer is not accessible to the user. One cannot query a clustered point. One cannot field calculate a @cluster_size attribute.

The point cluster renderer does inherit render order from the source using Control feature rendering order (QgsFeatureRequest::OrderByClause) leaving open the possibility of some clever workaround using attributes and expressions, however certain ordering schemes are not guaranteed to be consistent.

As an example, consider a point layer with rendering ordered ascending by a "Latitude" attribute. The more northerly points are rendered atop more southerly points. The point cluster renderer does not have a "Latitude" attribute for its new features, though it will inherit some semblance of that order from the source. There can be instances when a more southerly cluster renders atop a more northerly cluster, because of the order of the original points.

Related Question