<div dir="ltr">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?<br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Jun 24, 2021 at 9:43 AM Edouard Bourgine <<a href="mailto:edouard.bourgine@acosol.fr">edouard.bourgine@acosol.fr</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div lang="FR"><div class="gmail-m_4845219931750753823WordSection1"><p class="MsoNormal">Hi,<u></u><u></u></p><p class="MsoNormal"><u></u> <u></u></p><p class="MsoNormal">I’m running qgis 3.16 on w10.<u></u><u></u></p><p class="MsoNormal"><u></u> <u></u></p><p class="MsoNormal">I have two vector layers with multiple entities :<u></u><u></u></p><p class="gmail-m_4845219931750753823MsoListParagraph"><u></u><span style="font-family:Symbol"><span>·<span style="font:7pt "Times New Roman""> </span></span></span><u></u>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)<u></u><u></u></p><p class="gmail-m_4845219931750753823MsoListParagraph"><u></u><span style="font-family:Symbol"><span>·<span style="font:7pt "Times New Roman""> </span></span></span><u></u>The second with cropfields and meadows (polygon vector) (FIELD_LAYER)<u></u><u></u></p><p class="MsoNormal"><u></u> <u></u></p><p class="MsoNormal">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)<u></u><u></u></p><p class="MsoNormal"><u></u> <u></u></p><p class="MsoNormal">First i tried something like :<u></u><u></u></p><p class="gmail-m_4845219931750753823MsoListParagraph"><u></u><span style="font-family:Symbol"><span>·<span style="font:7pt "Times New Roman""> </span></span></span><u></u>Sum(area(intersection($geometry,geometry(‘FIELD_LAYER_ID’))),group_by :=FIELD WITH SAME VALUE EVERYWHERE)<u></u><u></u></p><p class="MsoNormal"><u></u> <u></u></p><p class="MsoNormal">But it is not a valid expression (geometry(‘FIELD_LAYER_ID’) don’t work)<u></u><u></u></p><p class="MsoNormal"><u></u> <u></u></p><p class="MsoNormal">Some meadows span over several town. Some juste inside one. <u></u><u></u></p><p class="MsoNormal">I’ve « cut » the FIELD_LAYER with the TOWN_LAYER<u></u><u></u></p><p class="MsoNormal"><u></u> <u></u></p><p class="MsoNormal">My first vector layer as a field specific and i’m looking for the formula that would give me the right answer.<u></u><u></u></p><p class="MsoNormal"><u></u> <u></u></p><p class="MsoNormal">I’ve tried :<u></u><u></u></p><p class="MsoNormal"><u></u> <u></u></p><p class="gmail-m_4845219931750753823MsoListParagraph"><u></u><span style="font-family:Symbol"><span>·<span style="font:7pt "Times New Roman""> </span></span></span><u></u>aggregate (layer :=’FIELD_LAYER_ID’, aggregate :=’sum’,expression :=$area, filter := intersects($geometry, geometry(@parent)))<u></u><u></u></p><p class="MsoNormal"><u></u> <u></u></p><p class="MsoNormal">It doesn’t work because the borders are overlapping : each fields just touching the borders even if they belong to another town are included.<u></u><u></u></p><p class="MsoNormal"><u></u> <u></u></p><p class="MsoNormal">« Contains » instead of « intersects » doesn’t work either because some borders of the field are overlapping and those are not included.<u></u><u></u></p><p class="MsoNormal"><u></u> <u></u></p><p class="MsoNormal">Exemple with « count » instead of « sum »<u></u><u></u></p><p class="MsoNormal"><u></u> <u></u></p><p class="MsoNormal">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.<u></u><u></u></p><p class="MsoNormal"><u></u> <u></u></p><p class="MsoNormal">I think the solution is with intersection, but i can’t reach a valid expression.<u></u><u></u></p><p class="MsoNormal"><u></u> <u></u></p><p class="MsoNormal">Another solution may be splitting the FIELD_LAYER in as much layer as town (I did that) and batch process for each layer :<u></u><u></u></p><p class="gmail-m_4845219931750753823MsoListParagraph"><u></u><span style="font-family:Symbol"><span>·<span style="font:7pt "Times New Roman""> </span></span></span><u></u>sum($area,group_by := FIELD WITH SAME VALUE EVERYWHERE)<u></u><u></u></p><p class="MsoNormal"><u></u> <u></u></p><p class="MsoNormal">then get the result in the TOWN_LAYER. <u></u><u></u></p><p class="MsoNormal"><u></u> <u></u></p><p class="MsoNormal">But i don’t know how to batch process it and get the result in the first layer.<u></u><u></u></p><p class="MsoNormal"><u></u> <u></u></p><p class="MsoNormal">And for informations I’m talking hundreds of towns and thousands of fields/meadows entities so one by one calculation is not possible.<u></u><u></u></p><p class="MsoNormal"><u></u> <u></u></p><p class="MsoNormal">I hope I make sense and that someone know how to deal with that.<u></u><u></u></p><p class="MsoNormal"><u></u> <u></u></p><p class="MsoNormal">Thanks,<u></u><u></u></p><p class="MsoNormal"><u></u> <u></u></p><p class="MsoNormal"><b><span style="font-family:"Arial","sans-serif"">Edouard BOURGINE<u></u><u></u></span></b></p><p class="MsoNormal"><i><span style="font-family:"Arial","sans-serif"">Ingénieur Environnement<u></u><u></u></span></i></p><p class="MsoNormal"><span style="font-family:"Arial","sans-serif""><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-family:"Arial","sans-serif"">Tél/Fax : 03.83.22.69.09<u></u><u></u></span></p><p class="MsoNormal"><span style="font-family:"Arial","sans-serif"">Port : 06.63.12.99.63<u></u><u></u></span></p><p class="MsoNormal"><span style="font-family:"Arial","sans-serif""><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-family:"Arial","sans-serif"">ACOSOL<u></u><u></u></span></p><p class="MsoNormal"><span style="font-family:"Arial","sans-serif"">26 rue de l’Ornain<u></u><u></u></span></p><p class="MsoNormal"><span style="font-family:"Arial","sans-serif"">54520 LAXOU<u></u><u></u></span></p><p class="MsoNormal"><u></u> <u></u></p></div><div id="gmail-m_4845219931750753823DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2"><br> <table style="border-top:1px solid rgb(211,212,222)">
<tbody><tr>
<td style="width:55px;padding-top:18px"><a href="https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=emailclient" target="_blank"><img src="https://ipmcdn.avast.com/images/icons/icon-envelope-tick-round-orange-animated-no-repeat-v1.gif" alt="" style="width: 46px; height: 29px;" width="46" height="29"></a></td>
<td style="width:470px;padding-top:17px;color:rgb(65,66,78);font-size:13px;font-family:Arial,Helvetica,sans-serif;line-height:18px">Garanti sans virus. <a href="https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=emailclient" style="color:rgb(68,83,234)" target="_blank">www.avast.com</a> </td>
</tr>
</tbody></table>
<a href="#m_4845219931750753823_DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2" width="1" height="1"> </a></div></div>_______________________________________________<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="https://lists.osgeo.org/mailman/listinfo/qgis-user" rel="noreferrer" target="_blank">https://lists.osgeo.org/mailman/listinfo/qgis-user</a><br>
Unsubscribe: <a href="https://lists.osgeo.org/mailman/listinfo/qgis-user" rel="noreferrer" target="_blank">https://lists.osgeo.org/mailman/listinfo/qgis-user</a><br>
</blockquote></div><br clear="all"><br>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div>Drew French</div><div>(715) 986-8088</div><div>www.ecologicaldesign.land<br></div></div></div>