Thursday 19 February 2015

python - Read from TIF overviews using rasterio


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.



Answer



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.



No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...