rasterio reproject code example

Example 1: 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)

Example 2: rasterio.warp.reproject

gdal_translate -of GTiff -co tiled=yes -co compress=LZW AMAZONIA.tif AMAZONIA_tiled.tif

Tags:

Misc Example