31QString QgsAlignSingleRasterAlgorithm::name()
const
33 return QStringLiteral(
"alignsingleraster" );
36QString QgsAlignSingleRasterAlgorithm::displayName()
const
38 return QObject::tr(
"Align raster" );
41QStringList QgsAlignSingleRasterAlgorithm::tags()
const
43 return QObject::tr(
"raster,align,resample,rescale" ).split(
',' );
46QString QgsAlignSingleRasterAlgorithm::group()
const
48 return QObject::tr(
"Raster tools" );
51QString QgsAlignSingleRasterAlgorithm::groupId()
const
53 return QStringLiteral(
"rastertools" );
56QString QgsAlignSingleRasterAlgorithm::shortHelpString()
const
58 return QObject::tr(
"Aligns raster by resampling it to the same cell size and reprojecting to the same CRS as a reference raster." );
61QgsAlignSingleRasterAlgorithm *QgsAlignSingleRasterAlgorithm::createInstance()
const
63 return new QgsAlignSingleRasterAlgorithm();
66void QgsAlignSingleRasterAlgorithm::initAlgorithm(
const QVariantMap & )
70 QStringList resamplingMethods;
71 resamplingMethods << QObject::tr(
"Nearest Neighbour" )
72 << QObject::tr(
"Bilinear (2x2 Kernel)" )
73 << QObject::tr(
"Cubic (4x4 Kernel)" )
74 << QObject::tr(
"Cubic B-Spline (4x4 Kernel)" )
75 << QObject::tr(
"Lanczos (6x6 Kernel)" )
76 << QObject::tr(
"Average" )
77 << QObject::tr(
"Mode" )
78 << QObject::tr(
"Maximum" )
79 << QObject::tr(
"Minimum" )
80 << QObject::tr(
"Median" )
81 << QObject::tr(
"First Quartile (Q1)" )
82 << QObject::tr(
"Third Quartile (Q3)" );
83 addParameter(
new QgsProcessingParameterEnum( QStringLiteral(
"RESAMPLING_METHOD" ), QObject::tr(
"Resampling method" ), resamplingMethods,
false, 0,
false ) );
84 addParameter(
new QgsProcessingParameterBoolean( QStringLiteral(
"RESCALE" ), QObject::tr(
"Rescale values according to the cell size" ),
false ) );
86 addParameter(
new QgsProcessingParameterCrs( QStringLiteral(
"CRS" ), QObject::tr(
"Override reference CRS" ), QVariant(),
true ) );
97 explicit QgsAlignRasterProgress(
QgsFeedback *feedback ) : mFeedback( feedback ) {}
98 bool progress(
double complete )
override
100 mFeedback->setProgress( complete * 100 );
111 QgsRasterLayer *inputLayer = parameterAsRasterLayer( parameters, QStringLiteral(
"INPUT" ), context );
115 QgsRasterLayer *referenceLayer = parameterAsRasterLayer( parameters, QStringLiteral(
"REFERENCE_LAYER" ), context );
116 if ( !referenceLayer )
119 const int method = parameterAsInt( parameters, QStringLiteral(
"RESAMPLING_METHOD" ), context );
120 const bool rescale = parameterAsBoolean( parameters, QStringLiteral(
"RESCALE" ), context );
121 const QString outputFile = parameterAsOutputLayer( parameters, QStringLiteral(
"OUTPUT" ), context );
167 item.resampleMethod = resampleAlg;
168 item.rescaleValues = rescale;
176 QString customCRSWkt;
177 QSizeF customCellSize;
178 QPointF customGridOffset( -1, -1 );
180 if ( parameters.value( QStringLiteral(
"CRS" ) ).isValid() )
186 bool hasXValue = parameters.value( QStringLiteral(
"CELL_SIZE_X" ) ).isValid();
187 bool hasYValue = parameters.value( QStringLiteral(
"CELL_SIZE_Y" ) ).isValid();
188 if ( ( hasXValue && !hasYValue ) || ( !hasXValue && hasYValue ) )
190 throw QgsProcessingException( QObject::tr(
"Either set both X and Y cell size values or keep both as 'Not set'." ) );
192 else if ( hasXValue && hasYValue )
194 double xSize = parameterAsDouble( parameters, QStringLiteral(
"CELL_SIZE_X" ), context );
195 double ySize = parameterAsDouble( parameters, QStringLiteral(
"CELL_SIZE_Y" ), context );
196 customCellSize = QSizeF( xSize, ySize );
199 hasXValue = parameters.value( QStringLiteral(
"GRID_OFFSET_X" ) ).isValid();
200 hasYValue = parameters.value( QStringLiteral(
"GRID_OFFSET_Y" ) ).isValid();
201 if ( ( hasXValue && !hasYValue ) || ( !hasXValue && hasYValue ) )
203 throw QgsProcessingException( QObject::tr(
"Either set both X and Y grid offset values or keep both as 'Not set'." ) );
205 else if ( hasXValue && hasYValue )
207 double xSize = parameterAsDouble( parameters, QStringLiteral(
"GRID_OFFSET_X" ), context );
208 double ySize = parameterAsDouble( parameters, QStringLiteral(
"GRID_OFFSET_Y" ), context );
209 customGridOffset = QPointF( xSize, ySize );
212 if ( parameters.value( QStringLiteral(
"EXTENT" ) ).isValid() )
214 QgsRectangle extent = parameterAsExtent( parameters, QStringLiteral(
"EXTENT" ), context );
223 throw QgsProcessingException( QObject::tr(
"It is not possible to reproject reference raster to target CRS." ) );
226 result = rasterAlign.
run();
233 outputs.insert( QStringLiteral(
"OUTPUT" ), outputFile );
GdalResampleAlgorithm
Resampling algorithm to be used (equivalent to GDAL's enum GDALResampleAlg)
@ RA_Lanczos
Lanczos windowed sinc interpolation (6x6 kernel)
@ RA_Q3
Third quartile (selects the third quartile of all non-NODATA contributing pixels)
@ RA_CubicSpline
Cubic B-Spline Approximation (4x4 kernel)
@ RA_Q1
First quartile (selects the first quartile of all non-NODATA contributing pixels)
@ RA_Min
Minimum (selects the minimum of all non-NODATA contributing pixels)
@ RA_Median
Median (selects the median of all non-NODATA contributing pixels)
@ RA_NearestNeighbour
Nearest neighbour (select on one input pixel)
@ RA_Average
Average (computes the average of all non-NODATA contributing pixels)
@ RA_Max
Maximum (selects the maximum of all non-NODATA contributing pixels)
@ RA_Bilinear
Bilinear (2x2 kernel)
@ RA_Mode
Mode (selects the value which appears most often of all the sampled points)
@ RA_Cubic
Cubic Convolution Approximation (4x4 kernel)
QFlags< ProcessingAlgorithmFlag > ProcessingAlgorithmFlags
Flags indicating how and when an algorithm operates and should be exposed to users.
@ PreferredGdal
Preferred format for conversion of CRS to WKT for use with the GDAL library.
@ HideFromToolbox
Algorithm should be hidden from the toolbox.
@ Double
Double/float values.
QgsAlignRaster takes one or more raster layers and warps (resamples) them so they have the same:
bool setParametersFromRaster(const RasterInfo &rasterInfo, const QString &customCRSWkt=QString(), QSizeF customCellSize=QSizeF(), QPointF customGridOffset=QPointF(-1, -1))
Set destination CRS, cell size and grid offset from a raster file.
bool run()
Run the alignment process.
void setClipExtent(double xmin, double ymin, double xmax, double ymax)
Configure clipping extent (region of interest).
void setProgressHandler(ProgressHandler *progressHandler)
Assign a progress handler instance. Does not take ownership. nullptr can be passed.
QList< QgsAlignRasterData::RasterItem > List
QString errorMessage() const
Returns the error from a previous run() call.
void setRasters(const List &list)
Sets list of rasters that will be aligned.
This class represents a coordinate reference system (CRS).
QString toWkt(Qgis::CrsWktVariant variant=Qgis::CrsWktVariant::Wkt1Gdal, bool multiline=false, int indentationWidth=4) const
Returns a WKT representation of this CRS.
Base class for feedback objects to be used for cancellation of something running in a worker thread.
QString source() const
Returns the source for the layer.
virtual Qgis::ProcessingAlgorithmFlags flags() const
Returns the flags indicating how and when the algorithm operates and should be exposed to users.
Contains information about the context in which a processing algorithm is executed.
Custom exception class for processing related exceptions.
Base class for providing feedback from a processing algorithm.
A boolean parameter for processing algorithms.
A coordinate reference system parameter for processing algorithms.
An enum based parameter for processing algorithms, allowing for selection from predefined values.
A rectangular map extent parameter for processing algorithms.
A numeric parameter for processing algorithms.
A raster layer destination parameter, for specifying the destination path for a raster layer created ...
A raster layer parameter for processing algorithms.
Represents a raster layer.
A rectangle specified with double values.
const QgsCoordinateReferenceSystem & crs
Definition of one raster layer for alignment.
Helper struct to be sub-classed for progress reporting.
virtual bool progress(double complete)=0
Method to be overridden for progress reporting.