Answers for "rasterio reproject python"

0

rasterio reproject python

import rasterio
from rasterio.warp import calculate_default_transform, reproject, Resampling
from fiona.crs import from_epsg
dst_crs = from_epsg(3413) #example of crs

with rasterio.open('my_raster.tif') 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('reprojected_raster.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=dst_crs,
                resampling=Resampling.nearest)
Posted by: Guest on March-20-2020

Python Answers by Framework

Browse Popular Code Answers by Language