On 19 October 2016 at 22:22, Neumann, Andreas <a.neum...@carto.net> wrote:
> Well yes - but that is not a "live" point in polygon. It create separate
> layers which need to be kept up-to-date.
>
> Harrissou was after a "live" point in polygon, which is automatically kept
> up-to-date through a QGIS expression.
>
> Maybe Nyall knows how to write the correct aggregate expression for that?

It's not possible using aggregate expressions at the moment - the
aggregate filters only have access to the child feature's attributes +
geometry, not the parent's.

I've been thinking about how to address this, and I'm leaning toward:

- attributes from the parent feature are automatically available
within the filter, UNLESS there's a duplicate field name from the
child feature
- expose the parent feature via the variable @parent. This could be
used with the functions geometry(@parent), attribute(@parent,
"some_dup_field_name")

Then you'd be able to write:

aggregate ('mypoint', 'count', "id", intersects ($geometry, geometry(@parent)))

The trickiest part in implementing this would be making sure the
current aggregate value cache correctly handles use of parent feature
attributes/geometry.

Re virtual layers: I've always seen these as a "heavier" (+ more
powerful!) approach, which is OK for some use cases but for others (Eg
data defined controls, composer labels, etc) it's preferable to have
these calculations available directly within the expression engine.


Nyall



>
> Greetings,
>
> Andreas
>
> On 2016-10-19 14:11, Nicolas Cadieux wrote:
>
>
> Try this.
>
> http://www.qgistutorials.com/fr/docs/points_in_polygon.html
>
> Nicolas
>
> Le 19 oct. 2016 à 06:37, DelazJ [via OSGeo.org] <[hidden email]> a écrit :
>
> Hi,
>
> I have a polygon layer and a point one.
> 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.
>
> I tried aggregate ('mypoint', 'count', "id", intersects ($geometry,
> geometry($currentfeature)))
>
>  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?
> 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.
> But I expected something more direct.
>
> Any hint, please?
>
> Thanks,
> Harrissou
>
> _______________________________________________
> Qgis-user mailing list
> [hidden email]
> List info: http://lists.osgeo.org/mailman/listinfo/qgis-user
> Unsubscribe: http://lists.osgeo.org/mailman/listinfo/qgis-user
>
> ________________________________
> If you reply to this email, your message will be added to the discussion
> below:
> http://osgeo-org.1560.x6.nabble.com/Using-aggregates-functions-to-count-intersected-features-from-another-layer-tp5291420.html
> To start a new topic under Quantum GIS - User, email [hidden email]
> To unsubscribe from Quantum GIS - User, click here.
> NAML
>
>
> ________________________________
> View this message in context: Re: Using aggregates functions to count
> intersected features from another layer
> Sent from the Quantum GIS - User mailing list archive at Nabble.com.
>
> _______________________________________________
> Qgis-user mailing list
> Qgis-user@lists.osgeo.org
> List info: http://lists.osgeo.org/mailman/listinfo/qgis-user
> Unsubscribe: http://lists.osgeo.org/mailman/listinfo/qgis-user
>
>
>
>
>
> _______________________________________________
> Qgis-user mailing list
> Qgis-user@lists.osgeo.org
> List info: http://lists.osgeo.org/mailman/listinfo/qgis-user
> Unsubscribe: http://lists.osgeo.org/mailman/listinfo/qgis-user
_______________________________________________
Qgis-user mailing list
Qgis-user@lists.osgeo.org
List info: http://lists.osgeo.org/mailman/listinfo/qgis-user
Unsubscribe: http://lists.osgeo.org/mailman/listinfo/qgis-user

Reply via email to