3

I am working on a QField project to take field data of trees, all inside a GeoPackage layer, working in QGIS version 3.40.5-Bratislava.

I have on one side a line data layer arbolado with its geometry and on the other side a non spatial table resumenespecies, both have a 1:m relationship (uui) and are related by a field called id_resumen. The logic of my form in QField is that the user:

  1. Would fill in the field num_arbol with the number of trees the user sees in the field first within the table arbolado.
  2. Then he would enter the relational table resumenespecies and distribute the number of trees that he has entered in num_arbol filling a field called esp_ud.

Within this table I have another field restantes that has to take the number of trees entered in the field esp_ud and subtract it from the total number of trees entered in the field num_tree to know how many trees are left to allocate. restantes= num_arbol - esp_ud The goal is to be distributed without going over between different types of forest species that you can also select in a field. In the end several fields will be generated in the relational table with respect to a single geometry (1:m).

I have tried to create the virtual field restantes with the expression:

aggregate(
 layer := 'arbolado',
 aggregate := 'sum',
 expression := "num_arbol",
 filter := "id_resumen" = "id_resumen"
) - "esp_ud"

Without success since it seems that it does not take into account just at that moment of creation of the form the data entered in num_arbol. I don't know if you know why it fails. Another expression I tried was:

attribute(@parent, 'num_arbol') - "esp_ud")

And I have also been working unsuccessfully on the expression

attribute( 
 get_feature('arbolado', 'id_resumen', "id_resumen"),
 'num_arbol'
 ) - "esp_ud"

The data I want to use with all this is from the last geometry record the user creates.

Vince
20.5k16 gold badges49 silver badges65 bronze badges
asked May 12 at 8:02

1 Answer 1

1

Try using the current_parent_value() function

Taras
35.8k5 gold badges77 silver badges151 bronze badges
answered May 12 at 16:37
2
  • At the moment it seems that the option you have told me is working correctly. Thank you very much. The way I have implemented it has been in the child table, within the field esp_ud, so that when I fill the num_arbol value of the arbolado table (parent table) and then I do the tree allocation as I said above, automatically appears the value of the num_arbol field in the esp_ud field. For new rows within the child table, the value that automatically appears in the field esp_ud is reduced as a result of subtracting num_arbol - esp_ud. Commented May 13 at 15:15
  • coalesce( current_parent_value('num_arbol'), 0 ) - coalesce( aggregate( 'resumenespecies', 'sum', "esp_ud", "id_resumen" = current_parent_value('id_resumen') ), 0 ) Commented May 13 at 15:20

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.