2

I'm trying to calculate the shared area for several overlapping areas. I need a dynamic solution in order to get automatically calculated statistics when drawing new polygons.

enter image description here

The target area is in this case the layer which contains the zoning plans. The other layer specifies the type of landuse (Markanvändning). The ultimate goal is to have a virtual field in the zoning layer, which grabs the information from the landuse-layer to define the share of different landuse-types (area) within the plan.

((aggregate(layer:='Markanvändning_e90475ff_88be_43f2_8eae_b14419c74d08', aggregate:='sum', expression:= (area(intersection($geometry, geometry(@parent)))), concatenator:=',',  filter:= "kategori" IS 'Offentlig'))/ "area_DP")*100

My approach was to create a virtual field within the zoning plan layer with an aggregate function, which calculates the share with the help of an intersect function. I created a test-layer and everything works fine if I just have one zoning-plan, but when I draw several plans I just get a result for the first row in my zoning plan layer.

enter image description here

What is going wrong here?

  • I don't see any obvious mistakes in that expression. Just to rule out one possibility: Are you sure that "Andel_Privat" and "Andel_Offentlig" are actually virtual fields? Because if you already had the first feature when you created these fields, and forgot to check the "virtual field" box, then you would have calculated values for the first feature, and NULL values any features you create later. – csk May 3 at 14:13
  • Yes I checked that, both are virtual fields. When I try to use to code as a standard expression in the field calculator I get this error message: "Couldn't calculate aggregation for: area(intersection($geometry, geometry(var('parent'))))"! If I just select the first row in the attribute table and try to use the code it works totally fine! – marc_mk May 3 at 15:39
  • Why do you think the error message has geometry(var('parent))? The expression in your question has it as geometry(@parent). – csk May 3 at 15:48
  • Actually I have no idea why it shows me the error message like that! I think it is basically the same just with a different style of expression. Tested it with the expression in the error message and I get the same result for the first row! – marc_mk May 3 at 15:56
  • I got a variation of your expression to work a couple times, but then I started getting the same error message. I think this is a bug. – csk May 3 at 16:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.