2

enter image description hereI am trying to build a very simple model in QGIS.

Simple intersection process (Density Zone-as intersection layer; watershed-as the other layer) followed by adding an "Area(ha)" field and finally the calculation of the population by multiplication of "Density Zone" field with "Area(ha)" field.

However, I want to add a table field parameter "Density Field" for example (density zone) which can be selected by the user from the "intersection layer". I couldn't call the field parameter value into the field calculator algorithm.

I tried typing the functions:

Density Field * "Area(ha)"

"Density Field" * "Area(ha)"

'Density Field' * "Area(ha)"

I searched for "advanced python don't calculator". I don't know python code syntax so I couldn't manage to do so. I also tried following texts in the advanced Python field calculator:

value= getvalue(<Density Zone>) * "Area(ha)"

value= getvalue(<Density Zone>) * (Area(ha))

All I wanted to do is to link the table field parameter into the functions' formula.


The problem is that a table field parameter cannot be introduced into a formula in order to create a new field.

Let's say there is a vector layer as an input. And another vector layer which will be used as an intersection layer. The first method is to intersect these two layers. The output of this intersection process will be used as a result layer but with further modifications. Secondly, in this processed layer, an area field will be added by the field calculator operator. Up to here, there is no problem.

Next, a second field will be created which is the multiplication of the area field previously created with the field which will be selected from the intersection layer (this field should be introduced as a "table field parameter" and must be selected by the user-user must know which field that is for this particular problem it is "density" field). The resulting output vector layer will have two new fields created which are "area" and "population" which is the multiplication of "area" and "density" fields.

I am struggling is how to type the multiplication formula by introducing the "table field parameter" (density) into the formula.

  • Is Area(ha) a valid field name? Does the model create this field? – aldo_tapia Nov 23 '17 at 13:57
  • Model creates it in the first part of the algorithm: add area field. This part does not have any problems. The problem is with the "table field parameter" and introducing it into the model. – Emre Hepgunes Nov 23 '17 at 14:18
  • I think the name isn't valid with parenthesis. If your coordinate reference system is in meters (i.e: UTM), better approach is to compute "Density Field" * $area/10000 – aldo_tapia Nov 23 '17 at 14:22
  • No. Area(ha) field is calculated properly. No problem with it. I have editted the question by adding a picture of the model and the problem. – Emre Hepgunes Nov 23 '17 at 14:27
  • The field name Area(ha) looks like a function, which might be confusing the field calculator. Try substituting a field name like Area_ha or AreaHA. – csk Nov 28 '17 at 21:07
1

I think you are looking for parameter function, just replace getValue with parameter.

From Advanced Python Field Calculator:

parameter('BUFFER_SIZE') → 5.6

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.