If you just run Intersection with FIELD as input and TOWN as overlay you
will get the data you need. You could join the TOWN and results layer using
a key. Is there a reason you need to use an expression?

On Thu, Jun 24, 2021 at 9:43 AM Edouard Bourgine <edouard.bourg...@acosol.fr>
wrote:

> Hi,
>
>
>
> I’m running qgis 3.16 on w10.
>
>
>
> I have two vector layers with multiple entities :
>
> ·         One with each town borders (? I’m note sure if this is the
> right word) I mean the area for each zip code. (TOWN_LAYER) (polygon vector)
>
> ·         The second with cropfields and meadows (polygon vector)
> (FIELD_LAYER)
>
>
>
> I want the total area of cropfield and Meadows in each Town from the first
> layer. (Exemple : one town have 31 fields/meadows -> total town area is
> 55km² (i have that info) and cropfield/meadows area is 26km² (i need that
> one for each town)
>
>
>
> First i tried something like :
>
> ·         
> Sum(area(intersection($geometry,geometry(‘FIELD_LAYER_ID’))),group_by :=FIELD
> WITH SAME VALUE EVERYWHERE)
>
>
>
> But it is not a valid expression (geometry(‘FIELD_LAYER_ID’) don’t work)
>
>
>
> Some meadows span over several town. Some juste inside one.
>
> I’ve « cut » the FIELD_LAYER with the TOWN_LAYER
>
>
>
> My first vector layer as a field specific and i’m looking for the formula
> that would give me the right answer.
>
>
>
> I’ve tried :
>
>
>
> ·         aggregate (layer :=’FIELD_LAYER_ID’,
> aggregate :=’sum’,expression :=$area, filter := intersects($geometry,
> geometry(@parent)))
>
>
>
> It doesn’t work because the borders are overlapping : each fields just
> touching the borders even if they belong to another town are included.
>
>
>
> « Contains » instead of « intersects » doesn’t work either because some
> borders of the field are overlapping and those are not included.
>
>
>
> Exemple with « count » instead of « sum »
>
>
>
> A town have 31 fields spanning over 26km² : Intersects give me a total
> count of 38 and 48km² and contains give me 12 and 4,7 km² because of
> borders overlap.
>
>
>
> I think the solution is with intersection, but i can’t reach a valid
> expression.
>
>
>
> Another solution may be splitting the FIELD_LAYER in as much layer as town
> (I did that) and batch process for each layer :
>
> ·         sum($area,group_by := FIELD WITH SAME VALUE EVERYWHERE)
>
>
>
> then get the result in the TOWN_LAYER.
>
>
>
> But i don’t know how to batch process it and get the result in the first
> layer.
>
>
>
> And for informations I’m talking hundreds of towns and thousands of
> fields/meadows entities so one by one calculation is not possible.
>
>
>
> I hope I make sense and that someone know how to deal with that.
>
>
>
> Thanks,
>
>
>
> *Edouard BOURGINE*
>
> *Ingénieur Environnement*
>
>
>
> Tél/Fax : 03.83.22.69.09
>
> Port : 06.63.12.99.63
>
>
>
> ACOSOL
>
> 26 rue de l’Ornain
>
> 54520 LAXOU
>
>
>
>
> <https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=emailclient>
>  Garanti
> sans virus. www.avast.com
> <https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=emailclient>
> <#m_4845219931750753823_DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>
> _______________________________________________
> Qgis-user mailing list
> Qgis-user@lists.osgeo.org
> List info: https://lists.osgeo.org/mailman/listinfo/qgis-user
> Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user
>


-- 
Drew French
(715) 986-8088
www.ecologicaldesign.land
_______________________________________________
Qgis-user mailing list
Qgis-user@lists.osgeo.org
List info: https://lists.osgeo.org/mailman/listinfo/qgis-user
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user

Reply via email to