Class: QgsAlignRaster¶
Takes one or more raster layers and warps (resamples) them to a common grid.
The aligned rasters will have the same:
coordinate reference system
cell size and raster size
offset of the raster grid
Note
This is an abstract class, with methods which must be implemented by a subclass.
The following methods must be implemented: progress()
Enums
alias of |
Methods
Returns the expected extent of the resulting aligned raster |
|
Returns the expected size of the resulting aligned raster |
|
Gets output cell size |
|
Determine destination extent from the input rasters and calculate derived values |
|
Gets clipping extent (region of interest). |
|
Internal function for processing of one raster (1. |
|
Gets the output CRS in WKT format |
|
write contents of the object to standard error stream - for debugging |
|
Returns the error from a previous |
|
Gets associated progress handler. |
|
Gets list of rasters that will be aligned |
|
Run the alignment process |
|
Sets output cell size |
|
Configure clipping extent (region of interest). |
|
Sets the output CRS in WKT format |
|
Set destination CRS, cell size and grid offset from a raster file. |
|
Assign a progress handler instance. |
|
Sets list of rasters that will be aligned |
|
Returns the index of the layer which has smallest cell size (returns -1 on error) |
Static Methods
Determine suggested output of raster warp to a different CRS. |
- class qgis.analysis.QgsAlignRaster[source]¶
Bases:
object
- Item¶
alias of
RasterItem
- class ProgressHandler¶
Bases:
object
Helper struct to be sub-classed for progress reporting
- 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
- class RasterInfo¶
Bases:
object
Utility class for gathering information about rasters
- 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:
- 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
- ResampleAlg¶
alias of
GdalResampleAlgorithm
- alignedRasterExtent(self) QgsRectangle [source]¶
Returns the expected extent of the resulting aligned raster
Note
first need to run
checkInputParameters()
which returns with success- Return type:
- alignedRasterSize(self) QSize [source]¶
Returns the expected size of the resulting aligned raster
Note
first need to run
checkInputParameters()
which returns with success- Return type:
QSize
- checkInputParameters(self) bool [source]¶
Determine destination extent from the input rasters and calculate derived values
- Return type:
bool
- Returns:
True
on success, sets error on error (seeerrorMessage()
)
- clipExtent(self) QgsRectangle [source]¶
Gets clipping extent (region of interest). No extra clipping is done if the rectangle is null
- Return type:
- createAndWarp(self, raster: QgsAlignRasterData.RasterItem) bool [source]¶
Internal function for processing of one raster (1. create output, 2. do the alignment)
- Parameters:
raster (QgsAlignRasterData.RasterItem)
- Return type:
bool
- errorMessage(self) str [source]¶
Returns the error from a previous
run()
call. Error message is empty ifrun()
succeeded (returnedTrue
)- Return type:
str
- progressHandler(self) QgsAlignRaster.ProgressHandler | None [source]¶
Gets associated progress handler. May be
None
(default)- Return type:
Optional[QgsAlignRaster.ProgressHandler]
- rasters(self) List[QgsAlignRasterData.RasterItem] [source]¶
Gets list of rasters that will be aligned
- Return type:
- run(self) bool [source]¶
Run the alignment process
- Return type:
bool
- Returns:
True
on success, sets error on error (seeerrorMessage()
)
- setCellSize(self, x: float, y: float)[source]¶
Sets output cell size
- Parameters:
x (float)
y (float)
- setCellSize(self, size: QSizeF)[source]
Sets output cell size
- Parameters:
size (QSizeF)
- setClipExtent(self, xmin: float, ymin: float, xmax: float, ymax: float)[source]¶
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)
- setClipExtent(self, extent: QgsRectangle)[source]
Configure clipping extent (region of interest). No extra clipping is done if the rectangle is null
- Parameters:
extent (
QgsRectangle
)
- setDestinationCrs(self, crsWkt: str | None)[source]¶
Sets the output CRS in WKT format
- Parameters:
crsWkt (Optional[str])
- setParametersFromRaster(self, rasterInfo: QgsAlignRaster.RasterInfo, customCRSWkt: str | None = '', customCellSize: QSizeF = QSizeF(), customGridOffset: QPointF | QPoint = QPointF(-1, -1)) bool [source]¶
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)- Parameters:
rasterInfo (QgsAlignRaster.RasterInfo)
customCRSWkt (Optional[str] = '')
customCellSize (QSizeF = QSizeF())
customGridOffset (Union[QPointF, QPoint] = QPointF(-1, -1))
- setParametersFromRaster(self, filename: str | None, customCRSWkt: str | None = '', customCellSize: QSizeF = QSizeF(), customGridOffset: QPointF | QPoint = QPointF(-1, -1)) bool [source]
Overridden variant for convenience, taking filename instead RasterInfo object. See the other variant for details.
- Parameters:
filename (Optional[str])
customCRSWkt (Optional[str] = '')
customCellSize (QSizeF = QSizeF())
customGridOffset (Union[QPointF, QPoint] = QPointF(-1, -1))
- Return type:
bool
- setProgressHandler(self, progressHandler: QgsAlignRaster.ProgressHandler | None)[source]¶
Assign a progress handler instance. Does not take ownership.
None
can be passed.- Parameters:
progressHandler (Optional[QgsAlignRaster.ProgressHandler])
- setRasters(self, list: Iterable[QgsAlignRasterData.RasterItem])[source]¶
Sets list of rasters that will be aligned
- Parameters:
list (Iterable[QgsAlignRasterData.RasterItem])
- suggestedReferenceLayer(self) int [source]¶
Returns the index of the layer which has smallest cell size (returns -1 on error)
- Return type:
int
- static suggestedWarpOutput(info: QgsAlignRaster.RasterInfo, destWkt: str | None, cellSize: QSizeF | None = None, gridOffset: QPointF | QPoint | None = None, rect: QgsRectangle | None = None) bool [source]¶
Determine suggested output of raster warp to a different CRS. Returns
True
on success- Parameters:
info (QgsAlignRaster.RasterInfo)
destWkt (Optional[str])
cellSize (Optional[QSizeF] = None)
gridOffset (Optional[Union[QPointF, QPoint]] = None)
rect (Optional[QgsRectangle] = None)
- Return type:
bool