23QString QgsFilterAlgorithm::name()
const
25 return QStringLiteral(
"filter" );
28QString QgsFilterAlgorithm::displayName()
const
30 return QObject::tr(
"Feature filter" );
33QStringList QgsFilterAlgorithm::tags()
const
35 return QObject::tr(
"filter,proxy,redirect,route" ).split(
',' );
38QString QgsFilterAlgorithm::group()
const
40 return QObject::tr(
"Modeler tools" );
43QString QgsFilterAlgorithm::groupId()
const
45 return QStringLiteral(
"modelertools" );
53QString QgsFilterAlgorithm::shortHelpString()
const
55 return QObject::tr(
"This algorithm filters features from the input layer and redirects them to one or several outputs." );
58QgsFilterAlgorithm *QgsFilterAlgorithm::createInstance()
const
60 return new QgsFilterAlgorithm();
63QgsFilterAlgorithm::~QgsFilterAlgorithm()
65 qDeleteAll( mOutputs );
68void QgsFilterAlgorithm::initAlgorithm(
const QVariantMap &configuration )
72 const QVariantList outputs = configuration.value( QStringLiteral(
"outputs" ) ).toList();
73 for (
const QVariant &output : outputs )
75 const QVariantMap outputDef = output.toMap();
76 const QString name = QStringLiteral(
"OUTPUT_%1" ).arg( outputDef.value( QStringLiteral(
"name" ) ).toString() );
80 if ( outputDef.value( QStringLiteral(
"isModelOutput" ) ).toBool() )
83 addParameter( outputParam );
84 mOutputs.append(
new Output( name, outputDef.value( QStringLiteral(
"expression" ) ).toString() ) );
91 std::unique_ptr<QgsProcessingFeatureSource> source( parameterAsSource( parameters, QStringLiteral(
"INPUT" ), context ) );
95 QgsExpressionContext expressionContext = createExpressionContext( parameters, context, source.get() );
96 for ( Output *output : std::as_const( mOutputs ) )
98 output->sink.reset( parameterAsSink( parameters, output->name, context, output->destinationIdentifier, source->fields(), source->wkbType(), source->sourceCrs() ) );
101 output->expression.prepare( &expressionContext );
104 long count = source->featureCount();
109 double step = count > 0 ? 100.0 / count : 1;
121 for ( Output *output : std::as_const( mOutputs ) )
123 if ( output->expression.evaluate( &expressionContext ).toBool() )
135 for (
const Output *output : std::as_const( mOutputs ) )
137 outputs.insert( output->name, output->destinationIdentifier );
139 qDeleteAll( mOutputs );
QFlags< ProcessingAlgorithmFlag > ProcessingAlgorithmFlags
Flags indicating how and when an algorithm operates and should be exposed to users.
QFlags< ProcessingParameterFlag > ProcessingParameterFlags
Flags which dictate the behavior of Processing parameters.
@ SkipGeometryValidityChecks
Invalid geometry checks should always be skipped. This flag can be useful for algorithms which always...
@ HideFromToolbox
Algorithm should be hidden from the toolbox.
@ Hidden
Parameter is hidden and should not be shown to users.
@ IsModelOutput
Destination parameter is final output. The parameter name will be used.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
void setFeature(const QgsFeature &feature)
Convenience function for setting a feature for the context.
Wrapper for iterator of features from vector data provider or vector layer.
bool nextFeature(QgsFeature &f)
Fetch next feature and stores in f, returns true on success.
This class wraps a request for features to a vector layer (or directly its vector data provider).
@ FastInsert
Use faster inserts, at the cost of updating the passed features to reflect changes made at the provid...
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
bool isCanceled() const
Tells whether the operation has been canceled already.
void setProgress(double progress)
Sets the current progress for the feedback object.
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.
void setFlags(Qgis::ProcessingParameterFlags flags)
Sets the flags associated with the parameter.
A feature sink output for processing algorithms.
An input feature source (such as vector layers) parameter for processing algorithms.