vrt.create_warped_vrt()

Create a warped VRT reprojecting a raster onto a fixed target grid.

Usage

Source

vrt.create_warped_vrt(
    src_path,
    output_vrt,
    *,
    crs,
    resolution,
    bounds=None,
    resampling=Resampling.average,
    snap=True,
    dtype=None,
    nodata=None
)

With snap, the grid origin grows outward to a multiple of resolution, so warps of several sources land on one common grid. Heights are shifted between vertical datums when both CRSs are compound or 3D.

Parameters

src_path: str | Path | UPath

Source raster; may be a VRT.

output_vrt: str | Path | UPath

Output VRT, written with an absolute source path so it can live anywhere.

crs: rasterio.crs.CRS or str

Target CRS.

resolution: float or tuple of float or None

Target pixel size, or (x, y) sizes, in units of crs. None takes the grid rasterio.warp.calculate_default_transform derives.

bounds: rasterio.coords.BoundingBox or tuple of float or None = None

Target extent as (left, bottom, right, top), in crs. Defaults to the reprojected extent of the source.

resampling: rasterio.enums.Resampling = Resampling.average

Warp kernel; average suits downsampling to a coarser target.

snap: bool = True

Snap the derived extent onto the target pixel grid. Ignored when bounds is given.

dtype: str or None = None

Data type of the warped band. Defaults to the source’s; promote to float so an averaging warp yields a mean, not a rounded count.

nodata: float or None = None
NODATA value of the warped band. Defaults to the source’s. Pass alongside dtype when the promoted type can’t hold the source’s sentinel, e.g. a 0 count becoming NaN.

Raises

ValueError
If resolution is not positive, bounds is given and does not lie on the resolution grid, no exact transformation is available (e.g. a datum grid is missing), only one of the source CRS and crs has a vertical datum, or the nodata (nodata, else the source’s) does not fit in the warped dtype.