Re: Unexpected result using rasterio windowed writing - Access window out of range in RasterIO()


umbertofilippo@...
 

Replying to myself to show my last update on the situation...

I have made some interesting improvements:

I am now able to write the full extent of raster `A` correctly over raster `B`, having the same pixel values in the same locations for both rasters.

The only thing left before having a complete solution is that the output raster has some (apparently regularly spaced) stripes, sign that there might be some adjustments to do in the window coordinates translation.

Here is a picture of the updated situation:



zoomed to see the stripes:



Finally, the updated code:

    with rasterio.open(inputfile, 'r') as src:
        with rasterio.open(
            os.path.join(dest_dir, 'mosaic2.tif'),
            'w',
            driver='GTiff',
            compress="DEFLATE",
            height=56160,
            width=85196,
            count=1,
            dtype=np.float64,
            crs='+proj=latlong',
            transform=out_transform,
        ) as mosaic_raster:
            for ji, window in src.block_windows(1):
                r = src.read(1, window=window)
                left, top = src.xy(
                    row=window.row_off,
                    col=window.col_off)
                right, bottom = src.xy(
                    row=window.row_off + window.height,
                    col=window.col_off + window.width)
                new_window = from_bounds(
                    left=left,
                    bottom=bottom,
                    right=right,
                    top=top,
                    transform=mosaic_raster.transform,
                    height=window.height,
                    width=window.width)
                mosaic_raster.write(r, 1, window=new_window)

Join main@rasterio.groups.io to automatically receive all group messages.