<div dir="ltr">Hi All, <div><br></div><div><br></div><div>Harrissou, have a look at [1] for a very similar question and one possible solution using the Function Editor (of course, instead of sum you would use count).</div><div><br></div><div>Do you other devs find that approach useful? Any hint for keeping the index up-to-date?</div><div><br></div><div>Is there any interest in having this kind of functions available for QGIS expressions? I could help with that.</div><div><br></div><div><br></div><div>Regards, </div><div><br></div><div>Germán</div><div>--</div><div>[1] <a href="http://gis.stackexchange.com/a/212762/4972">http://gis.stackexchange.com/a/212762/4972</a><br></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">2016-10-19 7:42 GMT-05:00 Neumann, Andreas <span dir="ltr"><<a href="mailto:a.neumann@carto.net" target="_blank">a.neumann@carto.net</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="font-size:10pt;font-family:Verdana,Geneva,sans-serif">
<p>Good idea to use a virtual layer for that! It is probably also more efficient than a QGIS expression.</p>
<p>Just to understand the virtual layers correctly:</p>
<p>when is the query behind the virtual layer executed?</p>
<p>- at every redraw?</p>
<p>- once at creation?</p>
<p>- at project reload?</p>
<p>Aren't the virtual layers automatically updated, at least when the project reloads?</p>
<p>Are the results cached or not?</p>
<p>Would also make sense to add a "update" option for a virtual layer, if that doesn't exist yet.</p>
<p>Greetings,</p>
<p>Andreas</p><div><div class="h5">
<p> </p>
<p>On 2016-10-19 14:32, Nathan Woodrow wrote:</p>
<blockquote type="cite" style="padding:0 0.4em;border-left:#1010ff 2px solid;margin:0">
<div dir="ltr">Maybe using a virtual layer query via DB Manager will work.  You have full SQL join support. Speed isn't always the best but gives you the full power of SQL which is the correct way to do this IMO.
<div> </div>
<div>E.g SELECT LayerA.id, COUNT(*) FROM layerA </div>
<div>JOIN layerB ON ST_WithIn(layerA.geometry, layerB.geometry)</div>
<div>GROUP BY layerA.type</div>
<div> </div>
<div>Although you can't do an update but you can make a new layer with the new counts.<br>
<div> </div>
<div>- Nathan</div>
</div>
</div>
<div class="gmail_extra"><br>
<div class="gmail_quote">On Wed, Oct 19, 2016 at 10:22 PM, Neumann, Andreas <span><<a href="mailto:a.neumann@carto.net" target="_blank">a.neumann@carto.net</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div style="font-size:10pt;font-family:Verdana,Geneva,sans-serif">
<p>Well yes - but that is not a "live" point in polygon. It create separate layers which need to be kept up-to-date.</p>
<p>Harrissou was after a "live" point in polygon, which is automatically kept up-to-date through a QGIS expression.</p>
<p>Maybe Nyall knows how to write the correct aggregate expression for that?</p>
<p>Greetings,</p>
<p>Andreas</p>
<div>
<div class="m_-566526819833031328h5">
<p>On 2016-10-19 14:11, Nicolas Cadieux wrote:</p>
</div>
</div>
<blockquote style="padding:0 0.4em;border-left:#1010ff 2px solid;margin:0">
<div>
<div class="m_-566526819833031328h5">
<div> </div>
<div>Try this.</div>
<div> </div>
<div><a href="http://www.qgistutorials.com/fr/docs/points_in_polygon.html" target="_blank">http://www.qgistutorials.com/f<wbr>r/docs/points_in_polygon.html</a></div>
<div> </div>
<div>Nicolas</div>
<div><br>Le 19 oct. 2016 à 06:37, DelazJ [via <a href="http://OSGeo.org" target="_blank">OSGeo.org</a>] <<a>[hidden email]</a>> a écrit :<br><br></div>
<blockquote style="border-left:2px solid #cccccc;padding:0 1em">
<div>
<div dir="ltr">
<div>
<div>
<div>
<div>
<div>
<div>Hi,<br><br></div>
I have a polygon layer and a point one.</div>
I'd like to calculate for each polygon feature, the number of points that it covers. I thought the aggregates functions could help me find an easier and straight expression to perform this (without creating intermediate layers) but I fail to find any correct syntax. <br><br></div>
I tried aggregate ('mypoint', 'count', "id", intersects ($geometry, geometry($currentfeature)))<br><br> And many variants of the fourth option but It always return the total of points or an error. Actually this option is a filter and I wonder if i'm not missing a "group by" option in the aggregate function (which seems to be the appropriate one in my case). Is it possible?</div>
</div>
<div>The work around I found is to populate an ad'hoc field in the point layer with overlapping polygon id, thanks to the SpatialJoin plugin, then I create a one-to-many relation in the project between the two layers in other to use relation_aggregate function.</div>
<div>But I expected something more direct.</div>
<div><br>Any hint, please?<br><br></div>
Thanks,</div>
Harrissou</div>
<br>______________________________<wbr>_________________ <br>Qgis-user mailing list <br><a>[hidden email]</a> <br>List info: <a href="http://lists.osgeo.org/mailman/listinfo/qgis-user" target="_blank">http://lists.osgeo.org/mailman<wbr>/listinfo/qgis-user</a><br>Unsubscribe: <a href="http://lists.osgeo.org/mailman/listinfo/qgis-user" target="_blank">http://lists.osgeo.org/mailman<wbr>/listinfo/qgis-user</a> <br><br><hr size="1">
<div style="color:#444;font:12px tahoma,geneva,helvetica,arial,sans-serif">
<div style="font-weight:bold">If you reply to this email, your message will be added to the discussion below:</div>
<a href="http://osgeo-org.1560.x6.nabble.com/Using-aggregates-functions-to-count-intersected-features-from-another-layer-tp5291420.html" target="_blank">http://osgeo-org.1560.x6.nabbl<wbr>e.com/Using-aggregates-functio<wbr>ns-to-count-intersected-<wbr>features-from-another-layer-<wbr>tp5291420.html</a></div>
<div style="color:#666;font:11px tahoma,geneva,helvetica,arial,sans-serif;margin-top:.4em;line-height:1.5em">To start a new topic under Quantum GIS - User, email <a>[hidden email]</a> <br> To unsubscribe from Quantum GIS - User, <a>click here</a>.<br><a style="font:9px serif" href="http://osgeo-org.1560.x6.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml" target="_blank">NAML</a></div>
</div>
</blockquote>
<br><hr align="left" width="300">View this message in context: <a href="http://osgeo-org.1560.x6.nabble.com/Using-aggregates-functions-to-count-intersected-features-from-another-layer-tp5291420p5291443.html" target="_blank">Re: Using aggregates functions to count intersected features from another layer</a><br> Sent from the <a href="http://osgeo-org.1560.x6.nabble.com/Quantum-GIS-User-f4125267.html" target="_blank">Quantum GIS - User mailing list archive</a> at Nabble.com.<br><br></div>
</div>
<div class="m_-566526819833031328m_-8854446165931069833pre" style="margin:0;padding:0;font-family:monospace">______________________________<wbr>_________________<br> Qgis-user mailing list<br><a href="mailto:Qgis-user@lists.osgeo.org" target="_blank">Qgis-user@lists.osgeo.org</a><span><br> List info: <a href="http://lists.osgeo.org/mailman/listinfo/qgis-user" target="_blank">http://lists.osgeo.org/mailman<wbr>/listinfo/qgis-user</a><br> Unsubscribe: <a href="http://lists.osgeo.org/mailman/listinfo/qgis-user" target="_blank">http://lists.osgeo.org/mailman<wbr>/listinfo/qgis-user</a></span></div>
</blockquote>
<p> </p>
<div> </div>
</div>
<br>______________________________<wbr>_________________<br> Qgis-user mailing list<br><a href="mailto:Qgis-user@lists.osgeo.org" target="_blank">Qgis-user@lists.osgeo.org</a><br> List info: <a href="http://lists.osgeo.org/mailman/listinfo/qgis-user" target="_blank">http://lists.osgeo.org/mailman<wbr>/listinfo/qgis-user</a><br> Unsubscribe: <a href="http://lists.osgeo.org/mailman/listinfo/qgis-user" target="_blank">http://lists.osgeo.org/mailman<wbr>/listinfo/qgis-user</a></blockquote>
</div>
</div>
</blockquote>
<p> </p>
<div> </div>
</div></div></div>
<br>______________________________<wbr>_________________<br>
Qgis-user mailing list<br>
<a href="mailto:Qgis-user@lists.osgeo.org">Qgis-user@lists.osgeo.org</a><br>
List info: <a href="http://lists.osgeo.org/mailman/listinfo/qgis-user" rel="noreferrer" target="_blank">http://lists.osgeo.org/<wbr>mailman/listinfo/qgis-user</a><br>
Unsubscribe: <a href="http://lists.osgeo.org/mailman/listinfo/qgis-user" rel="noreferrer" target="_blank">http://lists.osgeo.org/<wbr>mailman/listinfo/qgis-user</a><br></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div dir="ltr"><div>-----------<br></div><div>   |\__  <br>(:>__)(<br>   |/    <br>Soluciones Geoinformáticas Libres                            <br><a href="http://geotux.tuxfamily.org/" target="_blank">http://geotux.tuxfamily.org/</a><br><a href="http://twitter.com/GeoTux2" target="_blank">http://twitter.com/GeoTux2</a></div><div><a href="http://about.me/germancarrillo" target="_blank">http://about.me/germancarrillo</a><br></div><div><div><br></div><div><a href="http://gis.stackexchange.com/users/4972/germ%c3%a1n-carrillo" target="_blank"><img src="http://gis.stackexchange.com/users/flair/4972.png"></a></div></div></div></div></div></div></div>
</div>