Translating/shifting a raster in memory


matas.lauzadis@...
 

Hi all, I'm trying to apply dx, dy corrections to a DEM raster. This requires shifting the entire raster, and I was wondering if it is possible to do this in rasterio?


Sean Gillies
 

Hi,

On Mon, Feb 17, 2020 at 7:20 AM <matas.lauzadis@...> wrote:
Hi all, I'm trying to apply dx, dy corrections to a DEM raster. This requires shifting the entire raster, and I was wondering if it is possible to do this in rasterio?

If you open a rasterio dataset in "r+" mode, you can modify its transform attribute. Here's a code example:

from affine import Affine
import rasterio

with rasterio.open("example.tif",  "r+") as dataset:
    original_transform = dataset.transform
    new_transform = Affine.translation(dx, dy) * original_transform
    dataset.transform = new_transform

--
Sean Gillies