reproject raster python

Solutions on MaxInterview for reproject raster python by the best coders in the world

showing results for - "reproject raster python"
Bianca
14 Jan 2017
1import rasterio
2from rasterio.warp import calculate_default_transform, reproject, Resampling
3from fiona.crs import from_epsg
4dst_crs = from_epsg(3413) #example of crs
5
6with rasterio.open('my_raster.tif') as src:
7    transform, width, height = calculate_default_transform(src.crs, dst_crs, 
8                                                           src.width, 
9                                                           src.height, 
10                                                           *src.bounds)
11    kwargs = src.meta.copy()
12    kwargs.update({'crs': dst_crs,'transform': transform, 'width': width,'height': height})
13
14    with rasterio.open('reprojected_raster.tif', 'w', **kwargs) as dst:
15            reproject(source=rasterio.band(src, 1),destination=rasterio.band(dst, 1),
16                src_transform=src.transform,
17                src_crs=src.crs,
18                dst_transform=transform,
19                dst_crs=dst_crs,
20                resampling=Resampling.nearest)