ds.rst.reproject() or Raster.reproject()#
- RasterBase.reproject(ref=None, crs=None, res=None, grid_size=None, bounds=None, nodata=None, dtype=None, resampling=None, tolerance=0, apply_vertical=False, transformer_options=None, force_source_nodata=None, silent=False, inplace=False, n_threads=0, memory_limit=64, mp_config=None, nodata_propagation=None, overlap_backend='auto', error_structure=None, window=None, window_shape=None, coverage=None, area_weighting='diagonal_bounds', backend='auto', resampling_kwargs=None)[source]#
Reproject raster to a different geotransform (resolution, bounds) and/or coordinate reference system (CRS).
Match-reference: a reference raster can be passed to match resolution, bounds and CRS during reprojection.
Alternatively, the destination resolution, bounds and CRS can be passed individually.
Any resampling algorithm implemented in Rasterio can be passed as a string.
Rasters referenced by ground control points (GCPs) or rational polynomial coefficients (RPCs) use their stored model instead of the affine transform. Eager, lazy Dask and multiprocessing execution all support these models with Rasterio resampling methods. GCPs use their stored CRS; RPCs use WGS84 (EPSG:4326). The result has a regular affine grid.
The reprojection can be computed out-of-memory in multiprocessing by passing a
MultiprocConfigobject. The reprojected raster is written to disk under the path specified in the configuration- Parameters:
ref (
RasterType|str|None) – Reference raster to match resolution, bounds and CRS.crs (
CRS|str|int|None) – Destination coordinate reference system as a string or EPSG. Ifrefnot set, defaults to this raster’s CRS.res (
float|Iterable[float] |None) – Destination resolution (pixel size) in units of destination CRS. Single value or (xres, yres). Do not use withgrid_size.grid_size (
tuple[int,int] |None) – Destination grid size as (x, y). Do not use withres.bounds (
dict[str,float] |BoundingBox|None) – Destination bounds as a Rasterio bounding box, or a dictionary containing left, bottom, right, top bounds in the destination CRS.nodata (
int|float|None) – Destination nodata value. If set toNone, will use the same as source. If source does not exist, will use GDAL’s default.resampling (
Resampling|Literal['nearest','linear','bilinear','cubic','cubic_convolution','cubic_spline','lanczos','quintic','slinear','pchip','splinef2d','idw','inv_dist','kriging','mean','average','sum','median','med','quantile','q1','q3','mode','minimum','min','maximum','max','range','count','stdev','std','standard_deviation','rms','rmse','average_distance','average_distance_pts'] |Interpolator|Reducer|None) – Built-in method name, such as “linear”, “mean” or “median”. Advanced callers can supply an Interpolator or Reducer. By default, a Reducer weights source cells by their covered area. With GridNeighbours, it uses a fixed window around the transformed destination center. Defaults to bilinear. Can be configured with the global setting geoutils.config[“reprojection_method”]. See https://rasterio.readthedocs.io/en/stable/api/rasterio.enums.html#rasterio.enums.Resampling for the full list.backend (
Literal['auto','gdal','scipy','numba','gstools','gpytorch']) – “auto” preserves GDAL for supported string methods and uses SciPy for operator settings or other methods. “gdal” and “scipy” select one explicitly; “gstools” and “gpytorch” select kriging.resampling_kwargs (
dict[str,Any] |None) – Settings for a named method, such as a quantile q or a fitted kriging model.tolerance (
float) – Maximum error in source pixels when approximating a Rasterio warp transformation. Defaults to 0 for an exact transformation and consistent results across chunks. Positive values allow faster approximation but can produce different results across chunks. Requires Rasterio >= 1.5.apply_vertical (
bool) – Whether to apply the coordinate transformation’s vertical shift to raster values with Rasterio resampling. Use True for elevation values that need a vertical datum transformation. Applies even when the horizontal grid is unchanged. Defaults to False, so image values are only resampled. This does not control the ground height used to locate RPC pixels; useRPC_HEIGHTorRPC_DEMin transformer_options for that.transformer_options (
dict[str,Any] |None) – GDAL transformer options, such asRPC_DEMorRPC_HEIGHT, passed to grid calculation and reprojection. When both GCPs and RPCs are stored, select one with{"SRC_METHOD": "RPC"},{"SRC_METHOD": "GCP_POLYNOMIAL"}or{"SRC_METHOD": "GCP_TPS"}. Explicit reproject() arguments take precedence over options with the same name.force_source_nodata (
int|float|None) – Force a source nodata value (read from the metadata by default).inplace (
bool) – (DEPRECATED. Use rast = rast.reproject() instead) Whether to reproject in-place or not.silent (
bool) – Whether to print warning statements.n_threads (
int) – Number of threads. Defaults to (os.cpu_count() - 1).memory_limit (
int) – Memory limit in MB for warp operations. Larger values may perform better.mp_config (
MultiprocConfig|None) – Configuration object containing chunk size, output file path, and an optional cluster.nodata_propagation (
Literal['nearest','ignore','propagate'] |None) – How invalid source values affect a custom Interpolator or Reducer. By default, an Interpolator excludes invalid neighbors and masks a destination whose nearest source cell is invalid; a Reducer excludes invalid source cells and returns nodata if none are valid.ignoreexcludes invalid values without the nearest-cell mask;propagatereturns nodata if any contributing value is invalid.nearestexplicitly requests the default Interpolator rule.overlap_backend (
Literal['auto','numba','exactextract','shapely']) – Method used to calculate a Reducer’s cell overlap.autouses Numba for small unaligned grids when installed, then ExactExtract when installed, or Shapely.numba,exactextractandshapelyselect one explicitly. Aligned grids use direct overlap lengths.error_structure (
ErrorStructure|None) – Optional observation error model used for weighting and fitting. Use geoutils.uncertainty.propagate() to calculate output uncertainty.window (
int|None) – Odd source window size for a Reducer, overriding its configured neighborhood.window_shape (
Literal['square','circular'] |None) – Square or circular source window for a Reducer.coverage (
Literal['center','all_touched','fractional'] |None) – Select cells by center, include all touched cells, or weight by covered area. Without a fixed neighborhood, the default isfractional.area_weighting (
Literal['diagonal_bounds','intersection']) – For fractional reductions,diagonal_boundsweights the rectangle between two transformed diagonal corners. At the source boundary, its outer row or column also receives weight for the area extending beyond the raster.intersectionweights only the overlap of each source cell with the transformed four-corner destination polygon. Sums use the polygon in either mode.
- Return type:
RasterType|None- Returns:
Reprojected raster.