2

I have started to make a model in QGIS 2.2 graphical modeler. I have made a buffer around a polyline and used it to clip a polygon layer. So far i t works.

But the next step is to add a new column to the clipped polygon layer, and get that column to include rownumber? I have done this outside of the model before, but I don't understand how to make it work inside the model? I tried using the algorithm 'Field calculator' but it doesn't work.

How do I use the field calculator inside a model?

EDIT: Is there any other way of adding a column with rownumbers to the attribute table inside the model? I got the tip to use the 'Advanced Python field calculator' in an answer below, but I don't understand how to use it.

screenshot python field calculator

3
  • Hi,the field calculator that's available in the modeler works only with Python. The regular field calculator is not yet available. See: hub.qgis.org/issues/9402 Apr 30, 2014 at 10:43
  • OK, I'm pretty new at this, does that mean that I need to know programing to be able to use the calculator? Is there any other way besides the calculator to get the job done?
    – SoS
    Apr 30, 2014 at 11:06
  • @FilipeDias, I forgot to notify you in my previous comment. Do you know if there is anothor way besides the calculator? Without knowing programing?
    – SoS
    Apr 30, 2014 at 12:17

1 Answer 1

2

The Advanced Python Field Calculator works. The Syntax is a bit diffrent but value = $id should work.

3
  • I've tried that, but I don't seeem to get it right. I chose a name for the new field ('index') and put value = $rownum under 'Formula', and an output name. But when I tried to run the model, I get 'Error executing algorithm 2 __init__()takes exactly 2 arguments (4 given)'.
    – SoS
    May 2, 2014 at 7:01
  • Sry for the wrong statement. The documentation for the python calculator is only available in russian... value = $id works in my case.
    – Julian
    May 5, 2014 at 8:37
  • thank you for your update, that worked fine! If you update your answer with value = $id, I will set it as my accepted answer.
    – SoS
    May 5, 2014 at 11:08

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.