You want to get two information dynamically in your atlas.
Get the index of the current segment within the group of segment with the same Areas_AREA
You have to use an id that is unique for this operation. I would use RIN
for this but you can replace it with any id you have for your segment as long as it is in the same order that your atlas is ordered. You can use the formula array_agg()
to get an array (kind of list) of all the RIN
of segment that have Areas_AREA
equal to Areas_AREA
of your current segment. Then you can use array_find()
to get the index of your current segment inside this array. You have to add +1 because the first element of an array have index 0.
array_find(array_agg("RIN", filter:="Areas_AREA"=attribute (@atlas_feature,'Areas_AREA'),"RIN") +1
OR a calculation with more explicit values :
array_find ( aggregate( @atlas_layername, aggregate:='array_agg', expression:="RIN", filter:="Areas_AREA" =attribute (@atlas_feature ,'Areas_AREA')), "RIN" )+1
The result should be 1 for the first segment then 2 then 3, then when your segment is in another area it should start from 1 again.
The number of segment that have the same Areas_AREA
To get the number of segment that have the same area id you can use the formula count()
number of feature with Areas_AREA
equal with the attribute Areas_AREA
of your current atlas feature :
count(1, filter:="Areas_AREA" =attribute (@atlas_feature ,'Areas_AREA'))
The result should be a number equal to the number of feature for each area
Or you can also use array like before and use formula
array_length(array_agg("RIN", filter:="Areas_AREA"=attribute (@atlas_feature,'Areas_AREA'))
The final formula would be something like :
concat('Area: ',"Areas_AREA",' / ',maximum("Areas_AREA"),' | ','Segment: ',
array_find (aggregate( @atlas_layername, aggregate:='array_agg', expression:="RIN", filter:="Areas_AREA" =attribute (@atlas_feature ,'Areas_AREA')), "RIN" )+1,
'/',
count(1, filter:="Areas_AREA" =attribute (@atlas_feature ,'Areas_AREA')))
Note : To make atlas of atlas the report function could be useful and could add title page for each group of segment with specific maps.