1

Problem Description

I have been trying to create a dynamic layout in QGIS, such that the only parameter changing is the scale, and page width, map width, scalebar position, etc. are determined automatically. I am using the following expression to first find the lowest visible layer, of which I then extract the extent. Then I finally compute the layout size given the scale and extent.

(xmax(layer_property(array_last(array_filter( @layer_ids, is_layer_visible(@element) )), 'extent')) -
xmin(layer_property(array_last(array_filter( @layer_ids, is_layer_visible(@element) )), 'extent')))
* 1000 / round(@map_scale)

When using the expression on a Map Item, it works like a charm. But once I try to apply the same to the dimensions of the Page, the expression returns NULL. Similarly, for a Scalebar item, the expression fails to automatically return the correct coordinates. I have traced the error to the subexpression array_filter( @layer_ids, is_layer_visible(@element)), which returns an empty array.

Questions

Is this intended behavior due to some environment variables changing, and/or is there a fundamental misunderstanding of how expressions work in QGIS? Is there a workaround to still achieve what I am trying to do?

1
  • I find myself in the same boat as you. Did you manage to solve your problems by yourself. If so, I yould appreciate to hear about them.
    – RavenS
    Commented Jul 18 at 8:33

0

Your Answer

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

Browse other questions tagged or ask your own question.