I have a geodataframe with some bounds and I'd like to open that specifc box from the raster file. Lets say my raster file is name data.tiff so my current code is like:

import rasterio as rio
from rasterio.windows import from_bounds
with rio.open(data.tiff) as data:
    rst = data.read(1, window=from_bounds(bounds['left'], bounds['bot'], bounds['right'], bounds['top']))

But I get the following error:

WindowError: A transform object is required to calculate the window

What should my affine transform be if both the raster and the geodataframe are in the same coordinate system?


1 Answer 1


Just pass the raster dataset transform.

with rio.open(data.tiff) as data:
    rst = data.read(1, window=from_bounds(
        bounds['left'], bounds['bot'], bounds['right'], bounds['top'], 

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.