38 if ( !input.isValid() )
41 if ( qobject_cast< QgsRasterLayer * >( qvariant_cast<QObject *>( input ) ) )
46 if ( input.type() == QVariant::String )
48 if ( input.toString().isEmpty() )
57 else if ( input.type() == QVariant::List )
59 if ( input.toList().isEmpty() )
62 const QVariantList layerList = input.toList();
63 for (
const QVariant &variantLayer : layerList )
65 if ( qobject_cast< QgsRasterLayer * >( qvariant_cast<QObject *>( variantLayer ) ) )
68 if ( variantLayer.type() == QVariant::String )
77 else if ( variantLayer.type() == QVariant::Map )
79 const QVariantMap layerMap = variantLayer.toMap();
81 if ( !layerMap.contains( QStringLiteral(
"inputFile" ) ) && !layerMap.contains( QStringLiteral(
"outputFile" ) ) )
103 else if ( input.type() == QVariant::StringList )
105 const auto constToStringList = input.toStringList();
106 if ( constToStringList.isEmpty() )
112 for (
const QString &v : constToStringList )
126 const QList<QgsAlignRasterData::RasterItem> items =
parameterAsItems( value, context );
129 QStringList layerDefParts;
135 const QString layerDef = QStringLiteral(
"{%1}" ).arg( layerDefParts.join(
',' ) );
138 return parts.join(
',' ).prepend(
'[' ).append(
']' );
143 switch ( outputType )
147 QString code = QStringLiteral(
"QgsProcessingParameterAlignRasterLayers('%1', %2)" )
167 QList<QgsAlignRasterData::RasterItem> items;
169 if ( qobject_cast< QgsRasterLayer * >( qvariant_cast<QObject *>( layersVariant ) ) )
172 vm[
"inputFile"] = layersVariant;
176 if ( layersVariant.type() == QVariant::String )
179 vm[
"inputFile"] = layersVariant;
182 else if ( layersVariant.type() == QVariant::List )
184 const QVariantList layersVariantList = layersVariant.toList();
185 for (
const QVariant &layerItem : layersVariantList )
187 if ( layerItem.type() == QVariant::Map )
189 const QVariantMap layerVariantMap = layerItem.toMap();
192 else if ( layerItem.type() == QVariant::String )
195 vm[
"inputFile"] = layerItem;
200 else if ( layersVariant.type() == QVariant::StringList )
202 const auto layersStringList = layersVariant.toStringList();
203 for (
const QString &layerItem : layersStringList )
206 vm[
"inputFile"] = layerItem;
210 else if ( layersVariant.type() == QVariant::Map )
212 const QVariantMap layerVariantMap = layersVariant.toMap();
221 const QVariant layerVariant = layerVariantMap[ QStringLiteral(
"inputFile" ) ];
224 if ( ( inputLayer = qobject_cast< QgsRasterLayer * >( qvariant_cast<QObject *>( layerVariant ) ) ) )
240 item.
rescaleValues = layerVariantMap.value( QStringLiteral(
"rescale" ), false ).toBool();
249 vm[ QStringLiteral(
"resampleMethod" ) ] =
static_cast<int>( item.
resampleMethod );
GdalResampleAlgorithm
Flags which control how tiled scene 2D renderers behave.
Base class for all map layer types.
QString source() const
Returns the source for the layer.
Contains information about the context in which a processing algorithm is executed.
A parameter for Processing algorithms that need a list of input raster layers to align - this paramet...
QVariant valueAsJsonObject(const QVariant &value, QgsProcessingContext &context) const override
Returns a version of the parameter input value, which is suitable for use in a JSON object.
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const override
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
static QString typeName()
Returns the type name for the parameter class.
static QgsAlignRasterData::RasterItem variantMapAsItem(const QVariantMap &layerVariantMap, QgsProcessingContext &context)
Converts a QVariant value (a QVariantMap) to a single input layer.
QString type() const override
Unique parameter type name.
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
QgsProcessingParameterAlignRasterLayers(const QString &name, const QString &description=QString())
Constructor for QgsProcessingParameterAlignRasterLayers.
static QVariantMap itemAsVariantMap(const QgsAlignRasterData::RasterItem &item)
Converts a single input layer to QVariant representation (a QVariantMap)
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
static QList< QgsAlignRasterData::RasterItem > parameterAsItems(const QVariant &layersVariant, QgsProcessingContext &context)
Converts a QVariant value (a QVariantList) to a list of input layers.
QString valueAsString(const QVariant &value, QgsProcessingContext &context, bool &ok) const override
Returns a string version of the parameter input value (if possible).
Base class for the definition of processing parameters.
QString valueAsStringPrivate(const QVariant &value, QgsProcessingContext &context, bool &ok, ValueAsStringFlags flags) const
Internal method for evaluating values as string.
Flags mFlags
Parameter flags.
@ AllowMapLayerValues
Enable map layer value handling.
QString description() const
Returns the description for the parameter.
@ FlagOptional
Parameter is optional.
QString name() const
Returns the name of the parameter.
QVariant valueAsJsonObjectPrivate(const QVariant &value, QgsProcessingContext &context, ValueAsStringFlags flags) const
Internal method for evaluating values as JSON objects.
static QString stringToPythonLiteral(const QString &string)
Converts a string to a Python string literal.
static QString normalizeLayerSource(const QString &source)
Normalizes a layer source string for safe comparison across different operating system environments.
static QString variantToPythonLiteral(const QVariant &value)
Converts a variant to a Python literal.
static QgsMapLayer * mapLayerFromString(const QString &string, QgsProcessingContext &context, bool allowLoadingNewLayers=true, QgsProcessingUtils::LayerHint typeHint=QgsProcessingUtils::LayerHint::UnknownType, QgsProcessing::LayerOptionsFlags flags=QgsProcessing::LayerOptionsFlags())
Interprets a string as a map layer within the supplied context.
PythonOutputType
Available Python output types.
@ PythonQgsProcessingAlgorithmSubclass
Full Python QgsProcessingAlgorithm subclass.
Represents a raster layer.
Definition of one raster layer for alignment.
Qgis::GdalResampleAlgorithm resampleMethod
resampling method to be used
bool rescaleValues
rescaling of values according to the change of pixel size
QString inputFilename
filename of the source raster
QString outputFilename
filename of the newly created aligned raster (will be overwritten if exists already)