I am struggling with a task that seems like it should be quite simple. I have two rasters with the same size, resolution, CSR, but slightly different bounds. I need to perform a fairly simple calculation across, which requires that I align the two rasters. If I understand correctly, I need to perform some sort of reprojection on one of the rasters to align it with the other.
I see that there is function that provides a transform from the bounds, rasterio.transform.from_bounds(west, south, east, north, width, height), which seems like it would be the easiest way to go about this. Based on what I've found online, it seems like I need to do something like following to define and then apply the appropriate transform:
with rasterio.open('raster_1.tif') as src:
west, south, east, north = src.bounds
width = src.width'
height = src.height
transform = from_bounds(west, south, east, north, width, height)
kwargs = src.meta.copy()
kwargs.update({
'crs': src.crs,
'transform': transform,
'width': width,
'height': height})
with rasterio.open('raster_2.tif', 'w', **kwargs) as dst:
reproject(
source=rasterio.band(src, 1),
destination=rasterio.band(dst, 1),
src_transform=src.transform,
src_crs=src.crs,
dst_transform=transform,
dst_crs=src.crs,
resampling=Resampling.nearest)
When I check the bounds on the second raster, I see that it does indeed now line up with the first, except it seems that I have totally changed all of the data in raster. What have done wrong here?
dataset.transform
as the transform for thw windpw from bounds function..