Skip to main content
2 of 2
added 62 characters in body
gene
  • 55.4k
  • 3
  • 113
  • 191

In Python the with statement ensures that the file will be closed when leaving the processing therefore your raster is closed ( With statement in Python)

Therefore try:

dst_crs = 'EPSG:4326'
with rasterio.open(result_path + "\\" + "test_infra_{}.tif".format(product_group)) as src:
    transform, width, height = calculate_default_transform(src.crs, dst_crs, src.width, src.height, *src.bounds)
    kwargs = src.meta.copy()
    kwargs.update({'crs': dst_crs, 'transform': transform, 'width': width, 'height': height})
    with rasterio.open(result_path + "\\" + "test_infra_{}_wgs.tif".format(product_group), 'w', **kwargs) as dst:
        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=transform,
                dst_crs=dst_crs,
                resampling=Resampling.nearest)

and the src raster will not be closed in the second with

gene
  • 55.4k
  • 3
  • 113
  • 191