27using namespace Qt::StringLiterals;
36QString QgsAlignSingleRasterAlgorithm::name()
const
38 return u
"alignsingleraster"_s;
41QString QgsAlignSingleRasterAlgorithm::displayName()
const
43 return QObject::tr(
"Align raster" );
46QStringList QgsAlignSingleRasterAlgorithm::tags()
const
48 return QObject::tr(
"raster,align,resample,rescale" ).split(
',' );
51QString QgsAlignSingleRasterAlgorithm::group()
const
53 return QObject::tr(
"Raster tools" );
56QString QgsAlignSingleRasterAlgorithm::groupId()
const
58 return u
"rastertools"_s;
61QString QgsAlignSingleRasterAlgorithm::shortHelpString()
const
63 return QObject::tr(
"This algorithm aligns raster by resampling it to the same cell size and reprojecting to the same CRS as a reference raster." );
66QString QgsAlignSingleRasterAlgorithm::shortDescription()
const
68 return QObject::tr(
"Aligns raster by resampling it to the same cell size and reprojecting to the same CRS as a reference raster." );
71QgsAlignSingleRasterAlgorithm *QgsAlignSingleRasterAlgorithm::createInstance()
const
73 return new QgsAlignSingleRasterAlgorithm();
76void QgsAlignSingleRasterAlgorithm::initAlgorithm(
const QVariantMap & )
80 QStringList resamplingMethods;
81 resamplingMethods << QObject::tr(
"Nearest Neighbour" )
82 << QObject::tr(
"Bilinear (2x2 Kernel)" )
83 << QObject::tr(
"Cubic (4x4 Kernel)" )
84 << QObject::tr(
"Cubic B-Spline (4x4 Kernel)" )
85 << QObject::tr(
"Lanczos (6x6 Kernel)" )
86 << QObject::tr(
"Average" )
87 << QObject::tr(
"Mode" )
88 << QObject::tr(
"Maximum" )
89 << QObject::tr(
"Minimum" )
90 << QObject::tr(
"Median" )
91 << QObject::tr(
"First Quartile (Q1)" )
92 << QObject::tr(
"Third Quartile (Q3)" );
93 addParameter(
new QgsProcessingParameterEnum( u
"RESAMPLING_METHOD"_s, QObject::tr(
"Resampling method" ), resamplingMethods,
false, 0,
false ) );
108 QgsRasterLayer *inputLayer = parameterAsRasterLayer( parameters, u
"INPUT"_s, context );
112 QgsRasterLayer *referenceLayer = parameterAsRasterLayer( parameters, u
"REFERENCE_LAYER"_s, context );
113 if ( !referenceLayer )
116 const int method = parameterAsInt( parameters, u
"RESAMPLING_METHOD"_s, context );
117 const bool rescale = parameterAsBoolean( parameters, u
"RESCALE"_s, context );
118 const QString outputFile = parameterAsOutputLayer( parameters, u
"OUTPUT"_s, context );
164 item.resampleMethod = resampleAlg;
165 item.rescaleValues = rescale;
173 QString customCRSWkt;
174 QSizeF customCellSize;
175 QPointF customGridOffset( -1, -1 );
177 if ( parameters.value( u
"CRS"_s ).isValid() )
183 bool hasXValue = parameters.value( u
"CELL_SIZE_X"_s ).isValid();
184 bool hasYValue = parameters.value( u
"CELL_SIZE_Y"_s ).isValid();
185 if ( ( hasXValue && !hasYValue ) || ( !hasXValue && hasYValue ) )
187 throw QgsProcessingException( QObject::tr(
"Either set both X and Y cell size values or keep both as 'Not set'." ) );
189 else if ( hasXValue && hasYValue )
191 double xSize = parameterAsDouble( parameters, u
"CELL_SIZE_X"_s, context );
192 double ySize = parameterAsDouble( parameters, u
"CELL_SIZE_Y"_s, context );
193 customCellSize = QSizeF( xSize, ySize );
196 hasXValue = parameters.value( u
"GRID_OFFSET_X"_s ).isValid();
197 hasYValue = parameters.value( u
"GRID_OFFSET_Y"_s ).isValid();
198 if ( ( hasXValue && !hasYValue ) || ( !hasXValue && hasYValue ) )
200 throw QgsProcessingException( QObject::tr(
"Either set both X and Y grid offset values or keep both as 'Not set'." ) );
202 else if ( hasXValue && hasYValue )
204 double xSize = parameterAsDouble( parameters, u
"GRID_OFFSET_X"_s, context );
205 double ySize = parameterAsDouble( parameters, u
"GRID_OFFSET_Y"_s, context );
206 customGridOffset = QPointF( xSize, ySize );
209 if ( parameters.value( u
"EXTENT"_s ).isValid() )
211 QgsRectangle extent = parameterAsExtent( parameters, u
"EXTENT"_s, context );
217 explicit QgsAlignRasterProgress( QgsFeedback *feedback )
218 : mFeedback( feedback ) {}
219 bool progress(
double complete )
override
221 mFeedback->setProgress( complete * 100 );
226 QgsFeedback *mFeedback =
nullptr;
234 throw QgsProcessingException( QObject::tr(
"It is not possible to reproject reference raster to target CRS." ) );
237 result = rasterAlign.
run();
244 outputs.insert( u
"OUTPUT"_s, 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.
Takes one or more raster layers and warps (resamples) them to a common grid.
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.
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.
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.
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.