<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /></head><body style='font-size: 10pt; font-family: Verdana,Geneva,sans-serif'>
<p>Hi,</p>
<p>I have a basic example using aggregates:</p>
<p>----------------------</p>
<p>@qgsfunction(args='auto', group='Custom', usesgeometry=False)<br />def get_ews_anlage_nr(gemeinde, feature, parent):<br /> AnlageLayer = QgsMapLayerRegistry.instance().mapLayersByName('Anlage')[0]<br /> maxVal = AnlageLayer.aggregate(4,'to_int(substr("anlage_nr",4,4))')[0]<br /> return maxVal</p>
<p>-----------------------</p>
<p>But I still have two questions:</p>
<p>1. I still struggle to define a filter. I can't find the correct syntax how to define that filter string.</p>
<p>2. the first parameter "4" stands for "Max" aggregate (according to <a href="http://qgis-python.kartoza.com/docs/core/other/QgsAggregateCalculator.html#class-qgsaggregatecalculator">http://qgis-python.kartoza.com/docs/core/other/QgsAggregateCalculator.html#class-qgsaggregatecalculator</a> ). Could this code be written more "readable" by specifying "Max" instead of 4?</p>
<p>Thanks,</p>
<p>Andreas</p>
<p>On 2017-05-05 14:31, Neumann, Andreas wrote:</p>
<blockquote type="cite" style="padding: 0 0.4em; border-left: #1010ff 2px solid; margin: 0"><!-- html ignored --><!-- head ignored --><!-- meta ignored -->
<p>Hi,</p>
<p>Does someone have an example how to use QgsVectorLayer.aggregate() from Python?</p>
<p>How would the syntax for the parameters in the QgsAggregateCalculator.calculate() method look like in Python?</p>
<p>Thanks,</p>
<p>Andreas</p>
<div> </div>
<!-- html ignored --><br />
<div class="pre" style="margin: 0; padding: 0; font-family: monospace">_______________________________________________<br /> QGIS-Developer mailing list<br /><a href="mailto:QGIS-Developer@lists.osgeo.org">QGIS-Developer@lists.osgeo.org</a><br /> List info: <a href="https://lists.osgeo.org/mailman/listinfo/qgis-developer">https://lists.osgeo.org/mailman/listinfo/qgis-developer</a><br /> Unsubscribe: <a href="https://lists.osgeo.org/mailman/listinfo/qgis-developer">https://lists.osgeo.org/mailman/listinfo/qgis-developer</a></div>
</blockquote>
<p> </p>
<div> </div>
</body></html>