I´m creating a Qfield project in QGIS and I´m creating a Point-shapefile to work with in offline mode in the field.
In my project there are different plots where the field work will be developed. On each plot, trees will be sampled and registered as points (offline shapefile). When a point is created within one of these plots, the attribute value of the name of this plot will be transfered to a column of this point. Hence, it will be known in which plot the point was created. The name of the Plot is, for example, "P1".
When a point (tree) is created within a plot, the ID of this point is constructed as: Plot_ID + Tree_ID. Hence, it will be known where the tree was created and the ID of this tree within this plot. For example, the first tree recordered in the Plot 1, will be written as "P1B1". Then, the second will be written as "P1B2", and so on.
So far I´ve managed to set up the column of Tree_ID so that its ID number increases. This is, when several trees are created in the same plot, the values are created as expected: "P1B1"; "P1B2"; "P1B3". However, when I try to create another tree in a different plot, the plot is not differentiated, and the ID number continues increasing, rather than starting from 1 again. For example, if I create another tree in P2, the name will be wrongly created as "P2B4". This tree should be created as "P2B1", since this would be the first tree created within this plot.
After trying different approaches, the approach that gave me the result I was looking for is the following, where
Point_trees is the points-shp that are being created, and
plots_layer is the polygon-shp containing the plots where the field work will be made:
count('Point_trees', group_by:="Plot_ID", filter:= "Plot_ID"= aggregate(layer:='plots_layer', aggregate:='max', expression:="Name_of_plot", filter:=intersects($geometry, geometry(@parent))))+1
This code counts the number of features which
Plot_ID is equal to the actual
Plot_ID of the point which is being created (through the intersection part after