raster_tools.warp.reproject#

raster_tools.warp.reproject(raster, crs_or_geobox=None, resample_method='nearest', resolution=None)[source]#

Reproject to a new projection or resolution.

This is a lazy operation.

Parameters
  • raster (str, Raster) – The raster to reproject.

  • crs_or_geobox (int, str, CRS, GeoBox, optional) – The target grid to reproject the raster to. This can be a projection string, EPSG code string or integer, a CRS object, or a GeoBox object. When a CRS is given, the output grid is the default one GDAL suggests for the reprojection (see rasterio.warp.calculate_default_transform), which handles rasters that contain a pole or cross the antimeridian. GDAL picks the cell size from the distance between the raster’s corners, so the cells can be coarse for such rasters: a polar stereographic raster containing the pole becomes a few rows of cells a degree or more across in a geographic CRS. Pass resolution to get finer cells. resolution replaces GDAL’s cell size in the new CRS, keeping the grid’s top-left corner, and the grid is grown to whole cells so that it still covers GDAL’s extent. A geographic grid that this carries past latitude 90 or -90 is moved back to end at the pole; if its rows would span more than 180 degrees, their height is shortened so that they span -90 to 90 exactly. If crs_or_geobox is not provided, resolution must be specified.

  • resample_method (str, optional) –

    The data resampling method to use. Null pixels are ignored for all methods. Some methods require specific versions of GDAL. These are noted below. Valid methods are:

    ’nearest’

    Nearest neighbor resampling. This is the default.

    ’bilinear’

    Bilinear resampling.

    ’cubic’

    Cubic resampling.

    ’cubic_spline’

    Cubic spline resampling.

    ’lanczos’

    Lanczos windowed sinc resampling.

    ’average’

    Average resampling, computes the weighted average of all contributing pixels.

    ’mode’

    Mode resampling, selects the value which appears most often.

    ’max’

    Maximum resampling. (GDAL 2.0+)

    ’min’

    Minimum resampling. (GDAL 2.0+)

    ’med’

    Median resampling. (GDAL 2.0+)

    ’q1’

    Q1, first quartile resampling. (GDAL 2.0+)

    ’q3’

    Q3, third quartile resampling. (GDAL 2.0+)

    ’sum’

    Sum, compute the weighted sum. (GDAL 3.1+)

    ’rms’

    RMS, root mean square/quadratic mean. (GDAL 3.3+)

  • resolution (int, float, tuple of int or float, optional) – The desired resolution of the reprojected raster. If crs_or_geobox is unspecified, this is used to reproject to the new resolution while maintaining the same CRS. One of crs_or_geobox or resolution must be provided. Both can also be provided. Changing the resolution keeps the grid’s origin.

Returns

The reprojected raster on the new grid. Cells that the source does not cover are null. A raster with no null value is given the default null value for its dtype. Its valid cells stay valid, even where they hold that value, except in a 64-bit integer raster, where those cells are null or, with newer GDAL, have their value nudged off it. 64-bit integer values beyond 2**53 lose precision when reprojected, because GDAL warps them through double precision.

Return type

Raster