3

I am trying to create a visualisation method of simple stats using the title label in QGIS canvas. I need to observe temporal changes in the stats, so I have tried to specify a dynamic chunk of text in the title label that provides the stats of the visible features that looks like this:

[%concat(format_date(@map_start_time, 'yyyy-MM-dd'), ' to ', format_date(@map_end_time, 'yyyy-MM-dd'))%]

[%'Water level mean: '%][%aggregate(
 layer:= 'Lake',
 aggregate:='mean', 
 expression:="Lake water level (m)",
 filter:=(attribute( $currentfeature , 'Date (YYYYMMDD)')) ,
 concatenator:=',')%]

Range:

[% '+-' %] [%aggregate(
 layer:= 'Lake',
 aggregate:='range', 
 expression:="Lake water level (m)",
 filter:="Date (YYYYMMDD)",
 concatenator:=',')/2%]; 

Max: [%aggregate( layer:= 'Lake', aggregate:='max', expression:="Lake water level (m)", filter:="Date (YYYYMMDD)", concatenator:=',')%];

Min:

[%aggregate(
 layer:= 'Lake',
 aggregate:='min', 
 expression:="Lake water level (m)",
 filter:="Date (YYYYMMDD)",
 concatenator:=',')%]

However, these expressions only provide the layer stats, not the visible stats. My goal is to make those stats computed from the layer at each time period, so they relate to each visible time period. How can I do this?

1 Answer 1

3

Your issue is that the filter of your aggregate function is not a filter, but only an attribute. You need to add a comparison to actually make it a filter. Something like:

aggregate('Lake','mean',"Lake water level (m)",filter:="Date (YYYYMMDD)">=@map_start_time and "Date (YYYYMMDD)"<=@map_end_time)
3
  • Thanks for the reply Unfortunately, it did not resolve the issue, as the addition of a filter like that produced a NULL result, but I think it was a step in the right direction. Commented May 22, 2022 at 17:33
  • Then I suggest to check your datefield, especially if it is a real date and do some testings with just that field and map time variables in fieldcalculator (not decorations)
    – MrXsquared
    Commented May 22, 2022 at 19:44
  • In the suggested test, I managed to make it work. But only when creating a new DATE type field. It does not work when trying to use string type fields and their transformations to DateTime. This would be an interesting improvement to ease these operations, I think. Cheers Commented May 23, 2022 at 15:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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