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?

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

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.