vrt.warp()
Warp a raster or VRT onto another grid.
Usage
vrt.warp(
source,
*,
crs=None,
src_crs=None,
resolution=None,
bounds=None,
like=None,
resampling=Resampling.average,
snap=True,
dtype=None,
nodata=None,
tolerance="auto",
allow_ballpark=False
)The pixel type is not promoted: an averaging warp of a uint16 band stays uint16 and rounds the mean (1.5 becomes 2). Pass dtype="float32" to keep the fraction.
Parameters
source: str | Path | UPath | VRT-
Raster to warp; a VRT is embedded in the warp.
crs: CRS | str | None = None-
Target CRS; required unless
likeis given. src_crs: CRS | str | None = None-
Overrides the source’s CRS, e.g. to add the vertical datum its header lacks.
resolution: float | tuple[float, float] | None = None-
Target pixel size, or
(x, y)sizes, in units ofcrs.Nonetakes the gridrasterio.warp.calculate_default_transformderives. bounds: BoundingBox | tuple[float, float, float, float] | None = None-
Target extent as
(left, bottom, right, top)incrs, a whole number of pixels. Defaults to the reprojected extent of the source. Needsresolution. like: str | Path | UPath | VRT | None = None-
Raster whose CRS, transform and size are copied exactly.
resampling: Resampling = Resampling.average-
Warp kernel;
averagesuits downsampling to a coarser target. snap: bool = True-
Grow the derived extent outward onto the
resolutiongrid, so warps of several sources share one grid. Applies only withresolutionand withoutbounds. dtype: str | None = None-
Data type of the warped bands. Defaults to the source’s.
nodata: float | None = None-
NODATA value of the warped bands. Defaults to the source’s, which must then fit in
dtype. Pass it withdtypewhen the source’s sentinel should not stay a valid-looking value, e.g.nan. tolerance: float | {"auto"} = "auto"-
Error allowed when approximating the transformation, in source pixels;
0is exact."auto"is 0.125, or 0 when heights are shifted. allow_ballpark: bool = False- Let PROJ fall back to a ballpark transformation, ignoring datum differences, when it lacks a grid or a datum link.
Returns
VRT-
A warped VRT; nothing is written. Heights are shifted between vertical datums, and converted between vertical units, when the source CRS and
crsdiffer and both are compound or 3D; the source must then have one band and no scale or offset.
Raises
ValueError-
If neither
crsnorlikeis given,likecomes withcrs,resolutionorbounds,boundscomes withoutresolution,resolutionis not positive,boundsdoes not lie on theresolutiongrid,toleranceis negative or NaN, the source has no CRS and nosrc_crsis given, only one of the source CRS and the target CRS has a vertical datum, heights would be shifted in a source of more than one band or with a scale or offset, no exact transformation is available andallow_ballparkis false, the source has a colour table, or the nodata (the given one, else the source’s) does not fit in the warped dtype. RuntimeError- If GDAL’s serialized transformer cannot be made exact or ballpark-free.