30QString QgsAlignRastersAlgorithm::name()
const
32 return QStringLiteral(
"alignrasters" );
35QString QgsAlignRastersAlgorithm::displayName()
const
37 return QObject::tr(
"Align rasters" );
40QStringList QgsAlignRastersAlgorithm::tags()
const
42 return QObject::tr(
"raster,align,resample,rescale" ).split(
',' );
45QString QgsAlignRastersAlgorithm::group()
const
47 return QObject::tr(
"Raster tools" );
50QString QgsAlignRastersAlgorithm::groupId()
const
52 return QStringLiteral(
"rastertools" );
55QString QgsAlignRastersAlgorithm::shortHelpString()
const
57 return QObject::tr(
"Aligns rasters by resampling them to the same cell size and reprojecting to the same CRS." );
60QgsAlignRastersAlgorithm *QgsAlignRastersAlgorithm::createInstance()
const
62 return new QgsAlignRastersAlgorithm();
65bool QgsAlignRastersAlgorithm::checkParameterValues(
const QVariantMap ¶meters,
QgsProcessingContext &context, QString *message )
const
67 const QVariant layersVariant = parameters.value( parameterDefinition( QStringLiteral(
"LAYERS" ) )->name() );
69 bool unconfiguredLayers =
false;
72 if ( item.outputFilename.isEmpty() )
74 unconfiguredLayers =
true;
78 if ( unconfiguredLayers )
80 *message = QObject::tr(
"An output file is not configured for one or more input layers. Configure output files via 'Configure Raster…' under Input layers parameter." );
86void QgsAlignRastersAlgorithm::initAlgorithm(
const QVariantMap & )
91 addParameter(
new QgsProcessingParameterCrs( QStringLiteral(
"CRS" ), QObject::tr(
"Override reference CRS" ), QVariant(),
true ) );
103 explicit QgsAlignRasterProgress(
QgsFeedback *feedback ) : mFeedback( feedback ) {}
104 bool progress(
double complete )
override
106 mFeedback->setProgress( complete * 100 );
117 QgsRasterLayer *referenceLayer = parameterAsRasterLayer( parameters, QStringLiteral(
"REFERENCE_LAYER" ), context );
118 if ( !referenceLayer )
121 const QVariant layersVariant = parameters.value( parameterDefinition( QStringLiteral(
"LAYERS" ) )->name() );
123 QStringList outputLayers;
124 outputLayers.reserve( items.size() );
127 outputLayers << item.outputFilename;
133 QString customCRSWkt;
134 QSizeF customCellSize;
135 QPointF customGridOffset( -1, -1 );
137 if ( parameters.value( QStringLiteral(
"CRS" ) ).isValid() )
143 bool hasXValue = parameters.value( QStringLiteral(
"CELL_SIZE_X" ) ).isValid();
144 bool hasYValue = parameters.value( QStringLiteral(
"CELL_SIZE_Y" ) ).isValid();
145 if ( ( hasXValue && !hasYValue ) || ( !hasXValue && hasYValue ) )
147 throw QgsProcessingException( QObject::tr(
"Either set both X and Y cell size values or keep both as 'Not set'." ) );
149 else if ( hasXValue && hasYValue )
151 double xSize = parameterAsDouble( parameters, QStringLiteral(
"CELL_SIZE_X" ), context );
152 double ySize = parameterAsDouble( parameters, QStringLiteral(
"CELL_SIZE_Y" ), context );
153 customCellSize = QSizeF( xSize, ySize );
156 hasXValue = parameters.value( QStringLiteral(
"GRID_OFFSET_X" ) ).isValid();
157 hasYValue = parameters.value( QStringLiteral(
"GRID_OFFSET_Y" ) ).isValid();
158 if ( ( hasXValue && !hasYValue ) || ( !hasXValue && hasYValue ) )
160 throw QgsProcessingException( QObject::tr(
"Either set both X and Y grid offset values or keep both as 'Not set'." ) );
162 else if ( hasXValue && hasYValue )
164 double xSize = parameterAsDouble( parameters, QStringLiteral(
"GRID_OFFSET_X" ), context );
165 double ySize = parameterAsDouble( parameters, QStringLiteral(
"GRID_OFFSET_Y" ), context );
166 customGridOffset = QPointF( xSize, ySize );
169 if ( parameters.value( QStringLiteral(
"EXTENT" ) ).isValid() )
171 QgsRectangle extent = parameterAsExtent( parameters, QStringLiteral(
"EXTENT" ), context );
180 throw QgsProcessingException( QObject::tr(
"It is not possible to reproject reference raster to target CRS." ) );
183 result = rasterAlign.
run();
190 outputs.insert( QStringLiteral(
"OUTPUT_LAYERS" ), outputLayers );
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.
@ HideFromModeler
Algorithm should be hidden from the modeler.
@ 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.
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.
virtual bool checkParameterValues(const QVariantMap ¶meters, QgsProcessingContext &context, QString *message=nullptr) const
Checks the supplied parameter values to verify that they satisfy the requirements of this algorithm i...
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 multi-layer output for processing algorithms which create map layers, when the number and nature of...
A parameter for Processing algorithms that need a list of input raster layers to align - this paramet...
static QList< QgsAlignRasterData::RasterItem > parameterAsItems(const QVariant &layersVariant, QgsProcessingContext &context)
Converts a QVariant value (a QVariantList) to a list of input layers.
A coordinate reference system parameter for processing algorithms.
A rectangular map extent parameter for processing algorithms.
A numeric parameter for processing algorithms.
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.