[Qgis-user] Join attributes by location (summary) with condition

Ujaval Gandhi ujaval at spatialthoughts.com
Thu Jul 10 00:37:38 PDT 2025


You can use expressions to achieve this. I cover a similar problem of
conditional spatial join with an example in this
video https://www.youtube.com/watch?v=qpiFT8UHhwM
[https://l.shortlink.es/l/e53315961a63187508c99a5f2604e5ddbcf65c6f?u=8747767]


In your case, you can use the aggregate() expression with an additional filter
to select features where the attributes of both layers match. If the common
attribute name is 'direction', add a condition in the filter like "direction" =
attribute(@parent, 'direction') and specify the required statistic like 'mean',
'count' etc. as the aggregate.
---
Ujaval Gandhi
Spatial Thoughts
www.spatialthoughts.com
[https://l.shortlink.es/l/6911ea9a77e1c0ab611c66a0690a6d0ffc2b8ffd?u=8747767]




On Thu, Jul 10, 2025 at 1:01 PM Roland Spielhofer via QGIS-User
<qgis-user at lists.osgeo.org> wrote:

> Hi Chris,
> thanks for your suggestions!
>  
> The data is in Shapefiles, I do not have a PostGIS installation at hand...
>  
> What you mention is indeed what I am looking for - some statistical parameters
> (mean, count, min, max) of the points that fall into a polygon counting only
> the points that have the same direction attribute as the polygon.
> I will try with virtual layers.
>  
> Regards,
> Roland
> Gesendet: Mittwoch, 9. Juli 2025 um 15:28
> Von: "chris hermansen" <clhermansen at gmail.com [clhermansen at gmail.com]>
> An: "Roland Spielhofer" <rspiel at gmx.net [rspiel at gmx.net]>
> CC: qgis-user <qgis-user at lists.osgeo.org [qgis-user at lists.osgeo.org]>
> Betreff: Re: [Qgis-user] Join attributes by location (summary) with condition
> Roland and liat
> 
> [data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=3D]
> On Wed, Jul 9, 2025, 01:33 Roland Spielhofer via QGIS-User
> <qgis-user at lists.osgeo.org [qgis-user at lists.osgeo.org]> wrote:
> > Hi,
> > I am trying to get mean values from points lying inside polygons - that
> > would be easy with "join attributes by location (summary)".
> >  
> > But: I have overlapping polygons - coming from road segments (motorways with
> > separate lines per direction). The points and the polygons have a common
> > attribute ("+" or "-" per direction) .
> >  
> > I want to summarize the points of one direction that are lying inside the
> > polygon of the same direction.
> >  
> > Is there a way to achieve this?
> 
>  
> Are you able to use SQL?
>  
> This is a straightforward query in (for example) PostGIS, which offers spatial
> comparison operations such as "within"
>  
> https://postgis.net/docs/ST_Within.html
> [https://postgis.net/docs/ST_Within.html]
>  
> So if you select polygons and join the points using ST_within you can (for
> example) use GROUP BY and (for example) AVERAGE to get the average value of
> some attribute for all points within each polygon.
>  
> Is this the kind of thing you are looking for?
>  
> _______________________________________________
> QGIS-User mailing list
> QGIS-User at lists.osgeo.org [QGIS-User at lists.osgeo.org]
> List info: https://lists.osgeo.org/mailman/listinfo/qgis-user
> [https://lists.osgeo.org/mailman/listinfo/qgis-user]
> Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user
> [https://lists.osgeo.org/mailman/listinfo/qgis-user]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-user/attachments/20250710/5282dc85/attachment.htm>


More information about the QGIS-User mailing list