I'm reading a window of a tif using rasterio. How do I utilize the available overviews to get a down-sampled version of the data instead of reading at the true resolution?

Right now I am reading a window like this:

rmin, cmin = source.index(xmin, ymin)
rmax, cmax = source.index(xmax, ymax)
data = source.read(band, window=((rmax, rmin), (cmin, cmax)))

What I want to do:

rmin, cmin = source.index(xmin, ymin, use_overview=True)
rmax, cmax = source.index(xmax, ymax, use_overview=True)
data = source.read(band, window=((rmax, rmin), (cmin, cmax)), use_overview=True)

Any ideas? Note that in my case the overviews are internal, but any solution which reads off of overviews is great.

1 Answer 1


Answered at https://github.com/mapbox/rasterio/issues/710.

Example reading a 30x30 window into a 3x3 array where overviews (if available) would kick in.

arr = np.empty(shape=(3, 3)).astype(src.profile['dtype'])
arr = src.read(1, out=arr, window=((0, 30), (0, 30)))
arr array([[9195, 9116, 9134],
           [9158, 9144, 9085],
           [9010, 8935, 9002]], dtype=uint16)

Let me know if that works for you.

  • 1
    Does rasterio always use overviews if available? If perfectly-relevant overviews are unavailable, which algorithms does rasterio use to resample, and is it selectable? (Note e.g. nearest-neighbour and area-averaging give noticeably different outputs.) ..Perhaps should refer to GDAL docs to infer rasterio default behaviour..
    – benjimin
    Commented Oct 30, 2018 at 3:50

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.