Class: QgsAlignRaster

class qgis.analysis.QgsAlignRaster

Bases: sip.wrapper

QgsAlignRaster takes one or more raster layers and warps (resamples) them so they have the same: - coordinate reference system - cell size and raster size - offset of the raster grid

Methods

alignedRasterExtent

Returns the expected extent of the resulting aligned raster

alignedRasterSize

Returns the expected size of the resulting aligned raster

cellSize

Gets output cell size

checkInputParameters

Determine destination extent from the input rasters and calculate derived values

clipExtent

Gets clipping extent (region of interest).

createAndWarp

Internal function for processing of one raster (1.

destinationCrs

Gets the output CRS in WKT format

dump

write contents of the object to standard error stream - for debugging

errorMessage

Returns the error from a previous run() call.

gridOffset

rtype

QPointF

progressHandler

Gets associated progress handler.

rasters

Gets list of rasters that will be aligned

run

Run the alignment process

setCellSize

Sets output cell size

setClipExtent

Configure clipping extent (region of interest).

setDestinationCrs

Sets the output CRS in WKT format

setGridOffset

param offset

setParametersFromRaster

Set destination CRS, cell size and grid offset from a raster file.

setProgressHandler

Assign a progress handler instance.

setRasters

Sets list of rasters that will be aligned

suggestedReferenceLayer

Returns the index of the layer which has smallest cell size (returns -1 on error)

suggestedWarpOutput

Determine suggested output of raster warp to a different CRS.

Attributes

RA_Average

RA_Bilinear

RA_Cubic

RA_CubicSpline

RA_Lanczos

RA_Max

RA_Median

RA_Min

RA_Mode

RA_NearestNeighbour

RA_Q1

RA_Q3

class Item(input: str, output: str)

Bases: sip.wrapper

QgsAlignRaster.Item(QgsAlignRaster.Item)

Parameters
  • input (str) –

  • output (str) –

inputFilename
outputFilename
resampleMethod
rescaleValues
srcCellSizeInDestCRS
class ProgressHandler

Bases: sip.wrapper

QgsAlignRaster.ProgressHandler(QgsAlignRaster.ProgressHandler)

progress(self, complete: float) → bool

Method to be overridden for progress reporting.

Parameters

complete (float) – Overall progress of the alignment operation

Return type

bool

Returns

False if the execution should be canceled, True otherwise

RA_Average = 5
RA_Bilinear = 1
RA_Cubic = 2
RA_CubicSpline = 3
RA_Lanczos = 4
RA_Max = 8
RA_Median = 10
RA_Min = 9
RA_Mode = 6
RA_NearestNeighbour = 0
RA_Q1 = 11
RA_Q3 = 12
class RasterInfo(layerpath: str)

Bases: sip.wrapper

Construct raster info with a path to a raster file

Parameters

layerpath (str) –

bandCount(self) → int

Returns the number of raster bands in the file

Return type

int

cellSize(self) → QSizeF

Returns the cell size in map units

Return type

QSizeF

crs(self) → str

Returns the CRS in WKT format

Return type

str

dump(self)

Write contents of the object to standard error stream - for debugging

extent(self)QgsRectangle

Returns the extent of the raster

Return type

QgsRectangle

gridOffset(self) → QPointF

Returns the grid offset

Return type

QPointF

identify(self, mx: float, my: float) → float

Gets raster value at the given coordinates (from the first band)

Parameters
  • mx (float) –

  • my (float) –

Return type

float

isValid(self) → bool

Check whether the given path is a valid raster

Return type

bool

origin(self) → QPointF

Returns the origin of the raster

Return type

QPointF

rasterSize(self) → QSize

Returns the size of the raster grid in pixels

Return type

QSize

class ResampleAlg

Bases: int

alignedRasterExtent(self)QgsRectangle

Returns the expected extent of the resulting aligned raster

Note

first need to run checkInputParameters() which returns with success

Return type

QgsRectangle

alignedRasterSize(self) → QSize

Returns the expected size of the resulting aligned raster

Note

first need to run checkInputParameters() which returns with success

Return type

QSize

cellSize(self) → QSizeF

Gets output cell size

Return type

QSizeF

checkInputParameters(self) → bool

Determine destination extent from the input rasters and calculate derived values

Return type

bool

Returns

True on success, sets error on error (see errorMessage())

clipExtent(self)QgsRectangle

Gets clipping extent (region of interest). No extra clipping is done if the rectangle is null

Return type

QgsRectangle

createAndWarp(self, raster: QgsAlignRaster.Item) → bool

Internal function for processing of one raster (1. create output, 2. do the alignment)

Parameters

raster (QgsAlignRaster.Item) –

Return type

bool

destinationCrs(self) → str

Gets the output CRS in WKT format

Return type

str

dump(self)

write contents of the object to standard error stream - for debugging

errorMessage(self) → str

Returns the error from a previous run() call. Error message is empty if run() succeeded (returned True)

Return type

str

gridOffset(self) → QPointF
Return type

QPointF

progressHandler(self) → QgsAlignRaster.ProgressHandler

Gets associated progress handler. May be None (default)

Return type

QgsAlignRaster.ProgressHandler

rasters(self) → List[QgsAlignRaster.Item]

Gets list of rasters that will be aligned

Return type

List[QgsAlignRaster.Item]

run(self) → bool

Run the alignment process

Return type

bool

Returns

True on success, sets error on error (see errorMessage())

setCellSize(self, x: float, y: float)

Sets output cell size

setCellSize(self, size: QSizeF) Sets output cell size

Parameters
  • x (float) –

  • y (float) –

setClipExtent(self, xmin: float, ymin: float, xmax: float, ymax: float)

Configure clipping extent (region of interest). No extra clipping is done if the rectangle is null

setClipExtent(self, extent: QgsRectangle) Configure clipping extent (region of interest). No extra clipping is done if the rectangle is null

Parameters
  • xmin (float) –

  • ymin (float) –

  • xmax (float) –

  • ymax (float) –

setDestinationCrs(self, crsWkt: str)

Sets the output CRS in WKT format

Parameters

crsWkt (str) –

setGridOffset(self, offset: Union[QPointF, QPoint])
Parameters

offset (Union[QPointF) –

setParametersFromRaster(self, rasterInfo: QgsAlignRaster.RasterInfo, customCRSWkt: str = '', customCellSize: QSizeF = QSizeF(), customGridOffset: Union[QPointF, QPoint] = QPointF(- 1, - 1)) → bool

Set destination CRS, cell size and grid offset from a raster file. The user may provide custom values for some of the parameters - in such case only the remaining parameters are calculated.

If default CRS is used, the parameters are set according to the raster file’s geo-transform. If a custom CRS is provided, suggested reprojection is calculated first (using GDAL) in order to determine suitable defaults for cell size and grid offset.

Return type

bool

Returns

True on success (may fail if it is not possible to reproject raster to given CRS)

setParametersFromRaster(self, filename: str, customCRSWkt: str = ‘’, customCellSize: QSizeF = QSizeF(), customGridOffset: Union[QPointF, QPoint] = QPointF(-1,-1)) -> bool Overridden variant for convenience, taking filename instead RasterInfo object. See the other variant for details.

Parameters
  • rasterInfo (QgsAlignRaster.RasterInfo) –

  • customCRSWkt (str = '') –

  • customCellSize (QSizeF = QSizeF()) –

  • customGridOffset (Union[QPointF) –

setProgressHandler(self, progressHandler: QgsAlignRaster.ProgressHandler)

Assign a progress handler instance. Does not take ownership. None can be passed.

Parameters

progressHandler (QgsAlignRaster.ProgressHandler) –

setRasters(self, list: Iterable[QgsAlignRaster.Item])

Sets list of rasters that will be aligned

Parameters

list (Iterable[QgsAlignRaster.Item]) –

suggestedReferenceLayer(self) → int

Returns the index of the layer which has smallest cell size (returns -1 on error)

Return type

int

suggestedWarpOutput(info: QgsAlignRaster.RasterInfo, destWkt: str, cellSize: QSizeF = None, gridOffset: Union[QPointF, QPoint] = None, rect: QgsRectangle = None) → bool

Determine suggested output of raster warp to a different CRS. Returns True on success

Parameters
Return type

bool