3

I am new to QGIS and wish to automate my current process.

In my project I have to open the attribute table of the batch_16 layer having 5 fields (date, checked_by, td_created, td_catagor and op_comment).

There are 4 additional layers also (woody, sand, builtup, baresoil)

The logic is, if I make any new features in any of these 4 layers after jumping to a grid tile of batch_16 layer as shown in the pic, then I have to assign some attributes to the selected grid tile attribute field as below:

td_catagor: what layers I have worked on after pressing "zoom to selected" to the grid tile and before moving to another selection. woody - W, baresoil - B, sand - S, builtup - BU. If there are more than one layers I have created new features then each letter should be separated by comma as depicted in the image.

How can I automate this process?

Attributes

Layers

bumped to the homepage by Community 16 hours ago

This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.

0

I used AutoFields plugin in QGIS and entered expression as in the image and unchecked the "calculate expression on existing features."

AutoFields

0

Here's a way to automate your workflow. (Tested on QGIS 3.4)

Add a last_updated field to your 4 layers and set a default field value to the expression now(). This will ensure a timestamp is captured every time you make an edit to those layers.

The td_created and td_catagor should be setup as Virtual Fields so they are auto-updated based on an expression.

As you need to query another layer from your grid layer, you need to use the aggregate function. I am giving you example expression for 2 layers, woody and sand as the expression can get very long for the purpose of this answer. You can extend it for other layers. The expression assumes you have a field called last_checked in your grid layer.

For td_created, add a new virtual field with the following expression

if(
aggregate(
 layer:= 'woody',
 aggregate:='max',
 expression:=day(last_updated - attribute(@parent, 'last_checked')),
 filter:=intersects($geometry, geometry(@parent))
 ) > 0 

 OR

 aggregate(
 layer:= 'sand',
 aggregate:='max',
 expression:=day(last_updated - attribute(@parent, 'last_checked')),
 filter:=intersects($geometry, geometry(@parent))
 ) > 0, 'Y', 'N')

Similarly, add another virtual field td_categor with the following expression

array_to_string(
array_remove_all(array(
  if(aggregate(
   layer:= 'woody',
   aggregate:='max',
   expression:=day(last_updated - attribute(@parent, 'last_checked')),
   filter:=intersects($geometry, geometry(@parent))
   ) > 0, 'woody', 'none'),
  if(aggregate(
   layer:= 'sand',
   aggregate:='max',
   expression:=day(last_updated - attribute(@parent, 'last_checked')),
   filter:=intersects($geometry, geometry(@parent))
   ) > 0, 'sand', 'none')), 'none'))

This will add a comma-separated string with layer names like woody,sand

Now every-time you open the attribute table of the grid tile, these expressions will be evaluated and updated based on the timestamps in other layers.

I posted a more detailed explanation at https://spatialthoughts.com/2019/04/19/advanced-aggregate-expressions/

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.