I am currently trying to extract Web Mercator tiles from a Geotiff raster using rasterio VRT (version 1.0rc5). The tiles sometimes exceed the extent of the raster, which causes me trouble.
Reading the tile with
data = vrt.read(window=tile_window, out_shape=tile_shape) gives me corrupted result, instead of a cleanly cropped tile (I would expect to have NoData values out of the raster extent). According to the doc, the parameter
boundless=True seems to do what I want, but it does not work for WarpedVRT.
I am trying to find a workaround by adding a NoData buffer around my raster. Is it possible, and, if so, how can I do it?
My simplified code:
with rasterio.open(image) as src: extent = ... tile_shape = ... with WarpedVRT(src, crs='EPSG:3857', resampling=Resampling.bilinear) as vrt: # Window for reading the dataset tile_window = vrt.window(extent.x_min, extent.y_min, extent.x_max, extent.y_max) # Read tile content (boundless mode does not work yet for WarpedVRT) data = vrt.read(window=tile_window, out_shape=tile_shape)
Edit to illustrate the issue:
The tile I want to extract (there are 3 or 4 rows of pixels et the very bottom of the tile):
What I get from rasterio.vrt: