I want to co-register a DEM file with 100m resolution with a landcover file of 10m resolution. Thereby the DEM file is resampled to match the 10m resolution. Obviously, the file size of the new DEM will be bigger but in my case it is huge! (from 58kB to 136'927 kB). This seems not reasonably for me.
This is the code I use:
infile=os.path.join(f'DEM.tif')
match=os.path.join('landcover.tif') #co-register the infile to the match file
outfile=os.path.join('DEM_resampled.tif')
# open input
with rasterio.open(infile) as src:
src_transform = src.transform
# open input to match
with rasterio.open(match) as match:
dst_crs = match.crs
# calculate the output transform matrix
dst_transform, dst_width, dst_height = calculate_default_transform(
src.crs, # input CRS
dst_crs, # output CRS
match.width, # input width
match.height, # input height
*match.bounds, # unpacks input outer boundaries (left, bottom, right, top)
)
# set properties for output
dst_kwargs = src.meta.copy()
dst_kwargs.update({"crs": dst_crs,
"transform": dst_transform,
"width": dst_width,
"height": dst_height,
"nodata": 0})
print("Coregistered to shape:", dst_height,dst_width,'\n Affine',dst_transform)
# open output
with rasterio.open(outfile, "w", **dst_kwargs) as dst:
# iterate through bands and write using reproject function
for i in range(1, src.count + 1):
reproject(
source=rasterio.band(src, i),
destination=rasterio.band(dst, i),
src_transform=src.transform,
src_crs=src.crs,
dst_transform=dst_transform,
dst_crs=dst_crs,
resampling=Resampling.bilinear)
Does somebody have any tips?