2

I'm wondering how data-defined attributes work for the cluster symbol when using the point cluster layer styling in QGIS 3.*. How can you use the values of the points within the cluster for data-defined attributes?

The image below is the result of using the winddirection "D" attribute as the rotation parameter for the cluster symbol. It seems reasonable, however I don't know if this is the average, the sum, the mean or even the first value of the clustered points.

I would like to use the mean value of the clustered points, because I would like to get the prevailing winddirection. I tried using the expression mean( "D" ) but that results in all the points pointing the same direction. Documentation is a bit sparse and the only variables in the expression builder related to clustering that I can find are cluster_color and cluster_size which are both of no use in this case.

Here is the dataset if someone wants to try.

windfield

3

The cluster renderer is a relatively new feature of QGIS. As you've discovered, it only has two variables, cluster_color and cluster_size. It lacks variables like @currentcluster or similar, that would allow you to build an expression that refers to all of the points in a single cluster.

There is a recently-opened feature request for exactly this feature. I recommend watching that request for further developments.


In the meantime, your only option would be to generate your own point clusters.

One way is to generate a hexagonal grid, and symbolize it based on the average wind speed of the wind point it intersects.

Note: Unlike the cluster renderer, this method does not change cluster size based on zoom level. You would have to create a separate grid for every zoom level, and use scale-based visibility on each grid layer.

For example, my wind points layer is called 'wind' and the wind speed field is called 'speed'. Using the functions from the refFunctions plugin, I used this expression to calculate the average wind speed within each grid cell:

intersecting_geom_sum('wind','speed' )/ intersecting_geom_count( 'wind')

Add average wind speed and average wind direction as fields to the grid layer.

In case not every grid cell has a wind speed point in it, use this expression to define layer visibility:

"avg_wind_speed" > 0 and  "avg_wind_speed" is not null

Set up centroid fill symbology with two levels of marker:

  • One level is simple points.
  • The other level is a vector field. Use the fields "avg_wind_speed" and "avg_wind_direction" to control length and angle of the vector field.

In case not every grid cell has a wind speed point in it, use this expression to define layer visibility:

"avg_wind_speed" > 0 and  "avg_wind_speed" is not null

This gives a slightly random appearance to the point layout, although you can still see that the points are vertically aligned. If that's a problem, you could add a random data-defined offset to the centroid fill. Eg, define the x-coordinate as $x + rand(0,10) and likewise for the y-coordinate. Choose values for the rand() function that are appropriate to your layer units and scale.

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.