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

asked Oct 3, 2020 at 23:50
5
  • Just use the modeler and instead of having your input be the main layer just just the output from the previous alg... Commented Oct 4, 2020 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. Commented Oct 5, 2020 at 3: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. Commented Oct 5, 2020 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. Commented Oct 5, 2020 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. Commented Oct 5, 2020 at 20:46

0

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.