You just need to figure out the scale factor from your chosen and current pixel size, e.g. I want to resample this 10m resolution "input.tif" to 12.5m:
import rasterio from rasterio.enums import Resampling xres, yres = 12.5, 12.5 with rasterio.open("input.tif") as dataset: scale_factor_x = dataset.res[0]/xres scale_factor_y = dataset.res[1]/yres profile = dataset.profile.copy() # resample data to target shape data = dataset.read( out_shape=( dataset.count, int(dataset.height * scale_factor_y), int(dataset.width * scale_factor_x) ), resampling=Resampling.bilinear ) # scale image transform transform = dataset.transform * dataset.transform.scale( (1 / scale_factor_x), (1 / scale_factor_y) ) profile.update({"height": data.shape[-2], "width": data.shape[-1], "transform": transform}) with rasterio.open("output.tif", "w", **profile) as dataset: dataset.write(data)
And here's how the output looks (a single red 10m pixel over the output 12.5m pixels in greyscale): 