[QGIS-Developer] Python example with aggregate calculation

Neumann, Andreas a.neumann at carto.net
Fri May 5 06:55:45 PDT 2017


I have a basic example using aggregates: 


@qgsfunction(args='auto', group='Custom', usesgeometry=False)
def get_ews_anlage_nr(gemeinde, feature, parent):
AnlageLayer =
maxVal = AnlageLayer.aggregate(4,'to_int(substr("anlage_nr",4,4))')[0]
return maxVal 


But I still have two questions: 

1. I still struggle to define a filter. I can't find the correct syntax
how to define that filter string. 

2. the first parameter "4" stands for "Max" aggregate (according to
). Could this code be written more "readable" by specifying "Max"
instead of 4? 



On 2017-05-05 14:31, Neumann, Andreas wrote:

> Hi, 
> Does someone have an example how to use QgsVectorLayer.aggregate() from Python? 
> How would the syntax for the parameters in the QgsAggregateCalculator.calculate() method look like in Python? 
> Thanks, 
> Andreas
> _______________________________________________
> QGIS-Developer mailing list
> QGIS-Developer at lists.osgeo.org
> List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
> Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20170505/2dd2f3c9/attachment.html>

More information about the QGIS-Developer mailing list