1

I use an Atlas, and I would like to to display several features per page. To reach this aim, I would love to be able to use a fonction like attribute( @atlas_feature + 1 , 'field_1') to get the next feature data of field_1.

Is there a solution?

I guess a SQL solution for a custom function could do the trick?

1
  • 1
    If you have no filtering and sort by id that would be doable. Otherwise the other option that would be reliable is to create a python functioon with a feature_request that has the same parameters as your atlas and just get the feature after the current one. There would probably be an easier way with your data directly if it's in the same order.
    – Al rl
    Sep 7, 2022 at 0:11

1 Answer 1

2
+50

My understanding is that you want in a layout page whith two (or more) atlas feature. To make this easy to understand i will say you want half of a page about the current atlas feature (n) with a map, a table and a field of text. Then in the other half you get a map, a table and a field of text about the next atlas feature (n+1).

I assume you have a layout created for the atlas with the map, table and field of text based on the atlas feature on half of the page.

Sorting

To get the next atlas feature, you need to define and keep a field that will always be used for sorting.

Create an numeric field named order with the field calculator. It doesn't need to be continous just to get a clear ordering. Use this field in the atlas sorting. enter image description here

Get the next atlas feature

Now that you have an order you can get the next atlas feature using QGIS expressions.

Here is the formula to get the next atlas feature :

get_feature(                      -- to get next feature based on order
  @atlas_layerid , 
  'order', 
  minimum(                        -- to get the next value in order field
    'index_km_carrefour', 
    filter:= "order" > attribute( @atlas_feature, 'order' )
  )
)

Duplicate for atlas feature N+1

Then you have to duplicate map, table and field of text in your layout and modify it to make it work on next atlas feature.

For your map, desactivate controled by atlas and define the extent x_min with this formula :

with_variable (
'atlas_next_feature,'
get_feature(                      -- to get next feature based on order
  @atlas_layerid , 
  'order', 
  minimum(                        -- to get the next value in order field
    'index_km_carrefour', 
    filter:= "order" > attribute( @atlas_feature, 'order' )
  )
),
x_min (geometry( @atlas_next_feature))) 

For Y min, X max and Y max adapt the formula.

For your text field if you want to extract the value in the name field use this formula

with_variable (
'atlas_next_feature,'
get_feature(                      -- to get next feature based on order
  @atlas_layerid , 
  'order', 
  minimum(                        -- to get the next value in order field
    'index_km_carrefour', 
    filter:= "order" > attribute( @atlas_feature, 'order' )
  )
),
attribute (@atlas_next_feature,'name' )) 

Now it should look good and change when you change your atlas feature to alway get the next one... but you have duplicate.

Filter

When you export the complete atlas, you want to get each feature of your atlas layer only one time. For this, you will have to create an atlas page for one feature and not the next one.

To do this use the atlas filter with this formula :

with_variable (
'array_order',
array_agg( "order"),
array_contains(
    array_foreach(
        generate_series(0,array_length(@array_order)),
        if (
            @element/2 = to_int (@element/2),
            array_get (@array_order,@element),
            NULL
        )
    ), "order"
)

PS : all the formula seems pretty long but are made to work even if your order field contain not continuous list of value.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.