raster_tools.Raster.reproject#

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

Reproject to a new projection or resolution.

This is a lazy operation.

Parameters
  • 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, which can have coarse cells for rasters that contain a pole or cross the antimeridian. Pass resolution for finer cells. See raster_tools.reproject() for details. 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.

Return type

Raster