def warp(source_file, destination_file, dst_crs=None, resolution=None, dimensions=None,
         src_bounds=None, dst_bounds=None, src_nodata=None, dst_nodata=None,
         target_aligned_pixels=False, check_invert_proj=True,
         creation_options=None, resampling=Resampling.cubic, **kwargs):
    """Warp a raster dataset.

    Parameters
    ------------
    source_file: str, file object or pathlib.Path object
        Source file.
    destination_file: str, file object or pathlib.Path object
        Destination file.
    dst_crs: rasterio.crs.CRS, optional
        Target coordinate reference system.
    resolution: tuple (x resolution, y resolution) or float, optional
        Target resolution, in units of target coordinate reference
        system.
    dimensions: tuple (width, height), optional
        Output file size in pixels and lines.
    src_bounds: tuple (xmin, ymin, xmax, ymax), optional
        Georeferenced extent of output file from source bounds
        (in source georeferenced units).
    dst_bounds: tuple (xmin, ymin, xmax, ymax), optional
        Georeferenced extent of output file from destination bounds
        (in destination georeferenced units).
    src_nodata: int, float, or nan, optional
        Manually overridden source nodata.
    dst_nodata: int, float, or nan, optional
        Manually overridden destination nodata.
    target_aligned_pixels: bool, optional
        Align the output bounds based on the resolution.
        Default is `False`.
    check_invert_proj: bool, optional
        Constrain output to valid coordinate region in dst_crs.
        Default is `True`.
    creation_options: dict, optional
        Custom creation options.
    resampling: rasterio.enums.Resampling
        Reprojection resampling method. Default is `cubic`.
    kwargs: optional
        Additional arguments passed to transformation function.

    Returns
    ---------
    out: None
        Output is written to destination.
    """

    with rasterio.Env(CHECK_WITH_INVERT_PROJ=check_invert_proj):
        with rasterio.open(source_file) as src:
            out_kwargs = src.profile.copy()
            dst_crs, dst_transform, dst_width, dst_height = calc_transform(
                src, dst_crs, resolution, dimensions,
                src_bounds, dst_bounds, target_aligned_pixels)

            # If src_nodata is not None, update the dst metadata NODATA
            # value to src_nodata (will be overridden by dst_nodata if it is not None.
            if src_nodata is not None:
                # Update the destination NODATA value
                out_kwargs.update({
                    'nodata': src_nodata
                })

            # Validate a manually set destination NODATA value.
            if dst_nodata is not None:
                if src_nodata is None and src.meta['nodata'] is None:
                    raise ValueError('src_nodata must be provided because dst_nodata is not None')
                else:
                    out_kwargs.update({'nodata': dst_nodata})

            out_kwargs.update({
                'crs': dst_crs,
                'transform': dst_transform,
                'width': dst_width,
                'height': dst_height
            })

            # Adjust block size if necessary.
            if ('blockxsize' in out_kwargs and
                    dst_width < out_kwargs['blockxsize']):
                del out_kwargs['blockxsize']
            if ('blockysize' in out_kwargs and
                    dst_height < out_kwargs['blockysize']):
                del out_kwargs['blockysize']

            if creation_options is not None:
                out_kwargs.update(**creation_options)

            with rasterio.open(destination_file, 'w', **out_kwargs) as dst:
                reproject(
                    source=rasterio.band(src, src.indexes),
                    destination=rasterio.band(dst, dst.indexes),
                    src_transform=src.transform,
                    src_crs=src.crs,
                    src_nodata=src_nodata,
                    dst_transform=out_kwargs['transform'],
                    dst_crs=out_kwargs['crs'],
                    dst_nodata=dst_nodata,
                    resampling=resampling,
                    **kwargs)
def warp ( source_file , destination_file , dst_crs = None , resolution = None , dimensions = None , src_bounds = None , dst_bounds = None , src_nodata = None , dst_nodata = None , target_aligned_pixels = False , check_invert_proj = True , creation_options = None , resampling = Resampling . cubic , ** kwargs ) : with rasterio . Env ( CHECK_WITH_INVERT_PROJ = check_invert_proj ) : with rasterio . open ( source_file ) as src : out_kwargs = src . profile . copy ( ) dst_crs , dst_transform , dst_width , dst_height = calc_transform ( src , dst_crs , resolution , dimensions , src_bounds , dst_bounds , target_aligned_pixels ) if src_nodata is not None : out_kwargs . update ( { 'nodata' : src_nodata } ) if dst_nodata is not None : if src_nodata is None and src . meta [ 'nodata' ] is None : raise ValueError ( 'src_nodata must be provided because dst_nodata is not None' ) else : out_kwargs . update ( { 'nodata' : dst_nodata } ) out_kwargs . update ( { 'crs' : dst_crs , 'transform' : dst_transform , 'width' : dst_width , 'height' : dst_height } ) if ( 'blockxsize' in out_kwargs and dst_width < out_kwargs [ 'blockxsize' ] ) : del out_kwargs [ 'blockxsize' ] if ( 'blockysize' in out_kwargs and dst_height < out_kwargs [ 'blockysize' ] ) : del out_kwargs [ 'blockysize' ] if creation_options is not None : out_kwargs . update ( ** creation_options ) with rasterio . open ( destination_file , 'w' , ** out_kwargs ) as dst : reproject ( source = rasterio . band ( src , src . indexes ) , destination = rasterio . band ( dst , dst . indexes ) , src_transform = src . transform , src_crs = src . crs , src_nodata = src_nodata , dst_transform = out_kwargs [ 'transform' ] , dst_crs = out_kwargs [ 'crs' ] , dst_nodata = dst_nodata , resampling = resampling , ** kwargs )
Warp a raster dataset.

    Parameters
    ------------
    source_file: str, file object or pathlib.Path object
        Source file.
    destination_file: str, file object or pathlib.Path object
        Destination file.
    dst_crs: rasterio.crs.CRS, optional
        Target coordinate reference system.
    resolution: tuple (x resolution, y resolution) or float, optional
        Target resolution, in units of target coordinate reference
        system.
    dimensions: tuple (width, height), optional
        Output file size in pixels and lines.
    src_bounds: tuple (xmin, ymin, xmax, ymax), optional
        Georeferenced extent of output file from source bounds
        (in source georeferenced units).
    dst_bounds: tuple (xmin, ymin, xmax, ymax), optional
        Georeferenced extent of output file from destination bounds
        (in destination georeferenced units).
    src_nodata: int, float, or nan, optional
        Manually overridden source nodata.
    dst_nodata: int, float, or nan, optional
        Manually overridden destination nodata.
    target_aligned_pixels: bool, optional
        Align the output bounds based on the resolution.
        Default is `False`.
    check_invert_proj: bool, optional
        Constrain output to valid coordinate region in dst_crs.
        Default is `True`.
    creation_options: dict, optional
        Custom creation options.
    resampling: rasterio.enums.Resampling
        Reprojection resampling method. Default is `cubic`.
    kwargs: optional
        Additional arguments passed to transformation function.

    Returns
    ---------
    out: None
        Output is written to destination.