0

I have 5 layers:

  1. NAM_USA (It has four fields of our interest, named 'bare', 'sand', 'woody' and 'built' depicting feature counts in each of the below corresponding layers.)
  2. Baresoil
  3. Woodyland
  4. Sandbeach
  5. Builtup

The process is :

  1. Jump to a feature(grid) in NAM_USA using go2nextfeature plugin.
  2. Calculate predefined expressions on NAM_USA fields 'bare', 'sand', 'woody' and 'built'. The calculated values are before step 3 feature counts in layers 'Baresoil', 'Sandbeach', Woodyland' and 'Builtup' respectively.
  3. Make new features in layers 'Woodyland', 'Sandbeach', 'Baresoil' and 'Builtup' if any.
  4. Press "go to next feature". Now, before jumping to next grid tile, the plugin AutoField will execute some expressions on rest of the fields of NAM_USA based on the calculated values of 'bare', 'sand', 'woody' and 'built' in step 2 and current values.

At present I have to calculate expression on all four fields individually in step 2.

What I want : Calculate expression on all four fields in step 2 in a single click.

Is there any method or plugin or script by which I can reduce the efforts of calculating individually?

I do not have good knowledge of PyQGIS.

  • 2
    one hint : rephrase your question to make it more "understandable" ... – snaileater Apr 19 at 11:17
  • Done!!! Kindly see!! – Keshav Sharma Apr 19 at 11:35
  • If you can update to QGIS 3.4, you won't have to re-calculate your fields when you update the layer. QGIS 3 has virtual fields, which automatically stay up to date. This feature replaced the AutoField plugin. – csk Apr 19 at 18:39
  • Virtual fields also existed in QGIS v2.x. They do not replace the plugin AutoFields. Unlike Virtual Fields, the plugin AutoFields: 1) Stores the data directly into the data source, 2) Are independent of QGIS projects, i.e., you can switch between QGIS projects and AutoFields will still work; and 3) Only work on editable vector layers. – Germán Carrillo Apr 20 at 3:28
  • Virtual field do not seems to be updating its value in existing features....if I make a new grid tile then it does work, which is not the case here. My work is to make features in rest of the four layers at the NAM_USA layer tile's location and update attributes in the selected tile, which is whether the feature count increased or not. – Keshav Sharma Apr 20 at 8:33
0

Not sure i fully understand your question but ... :

In NAM_USA u can populate your 4 fields (bare,sand, woody, built) with the following expression :

intersecting_geom_count('bare_layer_name'), intersecting_geom_count('sand_layer_name') and so on ...

Any change made in the four layers should affect the columns of your NAM_USA layer (after leaving the edit mode of the underlying layers and having saved the edits made + maybe a little map refresh ...)

So nothing is calculated 'manually' ...

  • the expression is not seems to be workin in QGIS 2.18.12. currently I have added 4 project variables like Bare_count is written as (layer_property( 'Baresoil' , 'feature_count')). In field expression I use eval(@Bare_count) expression to get the feature counts. – Keshav Sharma Apr 19 at 13:35
  • mmm ... QGIS 2.18.12 maybe ... u didn't mention version in your question. i think intersecting_geom_count appeared in a next release of QGIS ... is the use of QGIS 2.18 mandatory for you ? What u have with your expression is a feature count by layer i think u're expecting a feature count by NAM_USA feature (or i don't understand your data structure...) – snaileater Apr 19 at 13:57
  • I HAVE EDITED THE QUESTION MORE SIMPLY. – Keshav Sharma Apr 19 at 17:21
  • Really lol ? ... u didn't answer my question : i suppose u're expecting feature count by grid (=NAM_USA feature) ? – snaileater Apr 19 at 17:26
  • intersecting_geom_count is part of the RefFunctions plugin, not part of any QGIS version. Install the plugin to get access to this function. – csk Apr 19 at 18:29
0

I've found a solution for this problem... the code in go2nextfeature plugin could be modified and hence I've added a button "update" in the plugin gui.

the code for the button is added after line 343, I've added

def btn_update_pressed(self):

    # self.ft_pos -= 1
    self.next_ft(-1)

   {my code here}

but I am not sure how to write the code to calculate the expression on the fields. some info can be found at Selecting and updating attribute values using Python console in QGIS

  • the expressions are like eval(@BARE) for field "bare" and so on... – Keshav Sharma Apr 20 at 10:37

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.