23 QString QgsFilterAlgorithm::name()
const
25 return QStringLiteral(
"filter" );
28 QString QgsFilterAlgorithm::displayName()
const
30 return QObject::tr(
"Feature filter" );
33 QStringList QgsFilterAlgorithm::tags()
const
35 return QObject::tr(
"filter,proxy,redirect,route" ).split(
',' );
38 QString QgsFilterAlgorithm::group()
const
40 return QObject::tr(
"Vector table" );
43 QString QgsFilterAlgorithm::groupId()
const
45 return QStringLiteral(
"vectortable" );
48 QgsProcessingAlgorithm::Flags QgsFilterAlgorithm::flags()
const
50 return FlagHideFromToolbox;
53 QString QgsFilterAlgorithm::shortHelpString()
const
55 return QObject::tr(
"This algorithm filters features from the input layer and redirects them to one or several outputs." );
58 QgsFilterAlgorithm *QgsFilterAlgorithm::createInstance()
const
60 return new QgsFilterAlgorithm();
63 QgsFilterAlgorithm::~QgsFilterAlgorithm()
65 qDeleteAll( mOutputs );
68 void 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() );
78 QgsProcessingParameterDefinition::Flags flags = QgsProcessingParameterDefinition::Flags();
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 : qgis::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 : qgis::as_const( mOutputs ) )
123 if ( output->expression.evaluate( &expressionContext ).toBool() )
134 for (
const Output *output : qgis::as_const( mOutputs ) )
136 outputs.insert( output->name, output->destinationIdentifier );
138 qDeleteAll( mOutputs );