2

Image a polygon layer with fields calculated from values found in a point layer. No witchcraft, there, as that's what we have all been doing for years.

The polygon layer needs to be populated with counts and aggregates coming from the point layer. This is an operation I will repeat many times during my work.

Here are some of the operations I will want to include. There are more like these.

Sum myNET
aggregate( layer:= 'MyPointLayer_aa66a666_a66a_666a_a6ab_6a6a6aa666', aggregate:= 'sum', expression:= myNET, filter:= contains(geometry(@parent), $geometry))

Sum myNET if myHZyear older than 2010, exclude WP in myHZtype aggregate( layer:= 'MyPointLayer_aa66a666_a66a_666a_a6ab_6a6a6aa666', aggregate:= 'sum', expression:= myNET, filter:= contains(geometry(@parent), $geometry) AND ("myHZyear" < 2010 OR "myHZyear" is null) AND "myHZtype" != 7206)

Sum myNET if myHZyear older than 2010, exclude WP and FW in myHZtype aggregate( layer:= 'MyPointLayer_aa66a666_a66a_666a_a6ab_6a6a6aa666', aggregate:= 'sum', expression:= myNET, filter:= contains(geometry(@parent), $geometry) AND ("myHZyear" < 2010 OR "myHZyear" is null) AND "myHZtype" != 7206 and "myHZtype" != 7208)

myNETperArea myNET / $area / 10000

Instead of doing a lot of clicking each time I have a point layer and a polygon layer and I need to do these calculations betwixt them, I would much prefer to store the calculations in one single operation. I tried in graphical modeler, but that produces one output layer per edited field and also a bunch of new layers. Is it possible to chain field calculator output so that the fields of the input layer are calculated in one go?

I have started to make a model with the graphical modeler with also some steps before what is described here and have also exported that model to a python script. If needed, I can of course dump the whole script here, but wouldn't want to do so right away if the question is clear enough as is.

Some questions I have considered, but nothing much came out of it:

Counting number of features within another feature using aggregating function in field calculator of QGIS?

Calculating point layer values within polygon features in QGIS 2

thymaro
  • 505
  • 3
  • 17
  • Just use the modeler and instead of having your input be the main layer just just the output from the previous alg... – Al rl Oct 04 '20 at 23:56
  • @Alrl yes. it's not the best solution, because layer:= 'MyPointLayer_... is hard-coded in the formula and I have to go into each of the steps and edit the string every time I have a new project with that chain of algorithms, but I guess it's still better than doing it manually each time. – thymaro Oct 05 '20 at 03:30
  • If your expressions are as you showed, its quite simple to do...I have seriously no idea why you are using the generic expliccit aggregate function instead of the proper ones. – Al rl Oct 05 '20 at 10:21
  • @Alrl I think I see what you mean. Should have thought of that. I'd rather not publish why I did it that way with the aggregate functions. :D I will try coming up with something what omits the field calculator in this case. – thymaro Oct 05 '20 at 14:57
  • Use the field calculator, just use the sum function if its what you need as by using the specific functions you don't need to specify the layer. – Al rl Oct 05 '20 at 20:46

0 Answers0