4

In QGIS (3.2), I'm using the Rasterize (vector to raster) in batch mode. This tool requires an output extent be set for each layer (leaving this parameter blank is not acceptable). I would like to autofill output extent using Calculate by expression. The extent should match the input layer's extent. What is the correct expression syntax to accomplish this?

asked Apr 20, 2022 at 16:02

1 Answer 1

5

Something like this should work.

It collects all the features of the input layer together and gets their bounds. The various components of the bounds are placed in an array which is finally converted to a (comma-separated) string.

with_variable(
 'bounds', 
 bounds(
 aggregate(
 @INPUT, -- the layer name is calculated from the tool input
 'collect', 
 $geometry
 ) 
 ),
 array_to_string( 
 array(
 x_min(@bounds),
 x_max(@bounds),
 y_min(@bounds),
 y_max(@bounds)
 )
 )
)

Example output from the Batch Processing dialog window after calculation:

8.167027224,9.826959383,38.880448354,41.246319006 [EPSG:4326]

The CRS is added automatically based on the input layer

answered Apr 20, 2022 at 16:21

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.