22 QString QgsExtractByExpressionAlgorithm::name()
 const 
   24   return QStringLiteral( 
"extractbyexpression" );
 
   27 QString QgsExtractByExpressionAlgorithm::displayName()
 const 
   29   return QObject::tr( 
"Extract by expression" );
 
   32 QStringList QgsExtractByExpressionAlgorithm::tags()
 const 
   34   return QObject::tr( 
"extract,filter,expression,field" ).split( 
',' );
 
   37 QString QgsExtractByExpressionAlgorithm::group()
 const 
   39   return QObject::tr( 
"Vector selection" );
 
   42 QString QgsExtractByExpressionAlgorithm::groupId()
 const 
   44   return QStringLiteral( 
"vectorselection" );
 
   47 void QgsExtractByExpressionAlgorithm::initAlgorithm( 
const QVariantMap & )
 
   57   addParameter( failOutput );
 
   60 QString QgsExtractByExpressionAlgorithm::shortHelpString()
 const 
   62   return QObject::tr( 
"This algorithm creates a new vector layer that only contains matching features from an input layer. " 
   63                       "The criteria for adding features to the resulting layer is based on a QGIS expression.\n\n" 
   64                       "For more information about expressions see the <a href =\"{qgisdocs}/user_manual/working_with_vector/expression.html\">user manual</a>" );
 
   67 QgsExtractByExpressionAlgorithm *QgsExtractByExpressionAlgorithm::createInstance()
 const 
   69   return new QgsExtractByExpressionAlgorithm();
 
   74   std::unique_ptr< QgsProcessingFeatureSource > source( parameterAsSource( parameters, QStringLiteral( 
"INPUT" ), context ) );
 
   78   QString expressionString = parameterAsExpression( parameters, QStringLiteral( 
"EXPRESSION" ), context );
 
   80   QString matchingSinkId;
 
   81   std::unique_ptr< QgsFeatureSink > matchingSink( parameterAsSink( parameters, QStringLiteral( 
"OUTPUT" ), context, matchingSinkId, source->fields(),
 
   82       source->wkbType(), source->sourceCrs() ) );
 
   86   QString nonMatchingSinkId;
 
   87   std::unique_ptr< QgsFeatureSink > nonMatchingSink( parameterAsSink( parameters, QStringLiteral( 
"FAIL_OUTPUT" ), context, nonMatchingSinkId, source->fields(),
 
   88       source->wkbType(), source->sourceCrs() ) );
 
   91   if ( expression.hasParserError() )
 
   96   QgsExpressionContext expressionContext = createExpressionContext( parameters, context, source.get() );
 
   98   long count = source->featureCount();
 
  100   double step = count > 0 ? 100.0 / count : 1;
 
  103   if ( !nonMatchingSink )
 
  128     expressionContext.
setFields( source->fields() );
 
  129     expression.prepare( &expressionContext );
 
  141       if ( expression.evaluate( &expressionContext ).toBool() )
 
  157   outputs.insert( QStringLiteral( 
"OUTPUT" ), matchingSinkId );
 
  158   if ( nonMatchingSink )
 
  159     outputs.insert( QStringLiteral( 
"FAIL_OUTPUT" ), nonMatchingSinkId );
 
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.
void setFields(const QgsFields &fields)
Convenience function for setting a fields for the context.
Class for parsing and evaluation of expressions (formerly called "search strings").
Wrapper for iterator of features from vector data provider or vector layer.
bool nextFeature(QgsFeature &f)
This class wraps a request for features to a vector layer (or directly its vector data provider).
QgsFeatureRequest & setFilterExpression(const QString &expression)
Set the filter expression.
QgsFeatureRequest & setExpressionContext(const QgsExpressionContext &context)
Sets the expression context used to evaluate filter expressions.
@ 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 SIP_HOLDGIL
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.
void setCreateByDefault(bool createByDefault)
Sets whether the destination should be created by default.
Custom exception class for processing related exceptions.
@ FlagSkipGeometryValidityChecks
Invalid geometry checks should always be skipped. This flag can be useful for algorithms which always...
Base class for providing feedback from a processing algorithm.
An expression parameter for processing algorithms.
A feature sink output for processing algorithms.
An input feature source (such as vector layers) parameter for processing algorithms.
@ TypeVector
Tables (i.e. vector layers with or without geometry). When used for a sink this indicates the sink ha...
@ TypeVectorAnyGeometry
Any vector layer with geometry.