23 void QgsLocationBasedAlgorithm::addPredicateParameter()
    26       QObject::tr( 
"Where the features (geometric predicate)" ),
    27       predicateOptionsList(), 
true, QVariant::fromValue( QList< int >() << 0 ) ) );
    29   QVariantMap predicateMetadata;
    30   QVariantMap widgetMetadata;
    31   widgetMetadata.insert( QStringLiteral( 
"class" ), QStringLiteral( 
"processing.gui.wrappers.EnumWidgetWrapper" ) );
    32   widgetMetadata.insert( QStringLiteral( 
"useCheckBoxes" ), 
true );
    33   widgetMetadata.insert( QStringLiteral( 
"columns" ), 2 );
    34   predicateMetadata.insert( QStringLiteral( 
"widget_wrapper" ), widgetMetadata );
    35   predicateParam->setMetadata( predicateMetadata );
    37   addParameter( predicateParam.release() );
    40 QgsLocationBasedAlgorithm::Predicate QgsLocationBasedAlgorithm::reversePredicate( QgsLocationBasedAlgorithm::Predicate predicate )
 const    65 QStringList QgsLocationBasedAlgorithm::predicateOptionsList()
 const    67   return QStringList() << QObject::tr( 
"intersect" )
    68          << QObject::tr( 
"contain" )
    69          << QObject::tr( 
"disjoint" )
    70          << QObject::tr( 
"equal" )
    71          << QObject::tr( 
"touch" )
    72          << QObject::tr( 
"overlap" )
    73          << QObject::tr( 
"are within" )
    74          << QObject::tr( 
"cross" );
    79     const QList< int > &selectedPredicates,
    80     const std::function < 
void( 
const QgsFeature & ) > &handleFeatureFunction,
    81     bool onlyRequireTargetIds,
    87   QList< Predicate > predicates;
    88   for ( 
int i : selectedPredicates )
    90     predicates << reversePredicate( static_cast< Predicate >( i ) );
    94   if ( predicates.contains( Disjoint ) )
   103   std::unique_ptr< QgsGeometryEngine > engine;
   116     if ( onlyRequireTargetIds )
   126       if ( foundSet.contains( testFeature.
id() ) )
   131       if ( predicates.count() == 1 && predicates.at( 0 ) == Disjoint && !disjointSet.contains( testFeature.
id() ) )
   140         engine->prepareGeometry();
   143       for ( Predicate predicate : qgis::as_const( predicates ) )
   145         bool isMatch = 
false;
   157               disjointSet.remove( testFeature.
id() );
   178           foundSet.insert( testFeature.
id() );
   179           handleFeatureFunction( testFeature );
   189   if ( predicates.contains( Disjoint ) )
   191     disjointSet = disjointSet.subtract( foundSet );
   193     if ( onlyRequireTargetIds )
   199       handleFeatureFunction( f );
   209 void QgsSelectByLocationAlgorithm::initAlgorithm( 
const QVariantMap & )
   211   QStringList methods = QStringList() << QObject::tr( 
"creating new selection" )
   212                         << QObject::tr( 
"adding to current selection" )
   213                         << QObject::tr( 
"select within current selection" )
   214                         << QObject::tr( 
"removing from current selection" );
   218   addPredicateParameter();
   220                 QObject::tr( 
"By comparing to the features from" ),
   224                 QObject::tr( 
"Modify current selection by" ),
   225                 methods, 
false, 0 ) );
   228 QString QgsSelectByLocationAlgorithm::name()
 const   230   return QStringLiteral( 
"selectbylocation" );
   233 QgsProcessingAlgorithm::Flags QgsSelectByLocationAlgorithm::flags()
 const   238 QString QgsSelectByLocationAlgorithm::displayName()
 const   240   return QObject::tr( 
"Select by location" );
   243 QStringList QgsSelectByLocationAlgorithm::tags()
 const   245   return QObject::tr( 
"select,intersects,intersecting,disjoint,touching,within,contains,overlaps,relation" ).split( 
',' );
   248 QString QgsSelectByLocationAlgorithm::group()
 const   250   return QObject::tr( 
"Vector selection" );
   253 QString QgsSelectByLocationAlgorithm::groupId()
 const   255   return QStringLiteral( 
"vectorselection" );
   258 QString QgsSelectByLocationAlgorithm::shortHelpString()
 const   260   return QObject::tr( 
"This algorithm creates a selection in a vector layer. The criteria for selecting "   261                       "features is based on the spatial relationship between each feature and the features in an additional layer." );
   264 QgsSelectByLocationAlgorithm *QgsSelectByLocationAlgorithm::createInstance()
 const   266   return new QgsSelectByLocationAlgorithm();
   271   QgsVectorLayer *selectLayer = parameterAsVectorLayer( parameters, QStringLiteral( 
"INPUT" ), context );
   273   std::unique_ptr< QgsFeatureSource > intersectSource( parameterAsSource( parameters, QStringLiteral( 
"INTERSECT" ), context ) );
   274   const QList< int > selectedPredicates = parameterAsEnums( parameters, QStringLiteral( 
"PREDICATE" ), context );
   277   auto addToSelection = [&]( 
const QgsFeature & feature )
   279     selectedIds.insert( feature.id() );
   281   process( context, selectLayer, intersectSource.get(), selectedPredicates, addToSelection, 
true, feedback );
   285   results.insert( QStringLiteral( 
"OUTPUT" ), parameters.value( QStringLiteral( 
"INPUT" ) ) );
   294 void QgsExtractByLocationAlgorithm::initAlgorithm( 
const QVariantMap & )
   298   addPredicateParameter();
   300                 QObject::tr( 
"By comparing to the features from" ),
   306 QString QgsExtractByLocationAlgorithm::name()
 const   308   return QStringLiteral( 
"extractbylocation" );
   311 QString QgsExtractByLocationAlgorithm::displayName()
 const   313   return QObject::tr( 
"Extract by location" );
   316 QStringList QgsExtractByLocationAlgorithm::tags()
 const   318   return QObject::tr( 
"extract,filter,intersects,intersecting,disjoint,touching,within,contains,overlaps,relation" ).split( 
',' );
   321 QString QgsExtractByLocationAlgorithm::group()
 const   323   return QObject::tr( 
"Vector selection" );
   326 QString QgsExtractByLocationAlgorithm::groupId()
 const   328   return QStringLiteral( 
"vectorselection" );
   331 QString QgsExtractByLocationAlgorithm::shortHelpString()
 const   333   return QObject::tr( 
"This algorithm creates a new vector layer that only contains matching features from an "   334                       "input layer. The criteria for adding features to the resulting layer is defined "   335                       "based on the spatial relationship between each feature and the features in an additional layer." );
   338 QgsExtractByLocationAlgorithm *QgsExtractByLocationAlgorithm::createInstance()
 const   340   return new QgsExtractByLocationAlgorithm();
   345   std::unique_ptr< QgsFeatureSource > input( parameterAsSource( parameters, QStringLiteral( 
"INPUT" ), context ) );
   346   std::unique_ptr< QgsFeatureSource > intersectSource( parameterAsSource( parameters, QStringLiteral( 
"INTERSECT" ), context ) );
   347   const QList< int > selectedPredicates = parameterAsEnums( parameters, QStringLiteral( 
"PREDICATE" ), context );
   349   std::unique_ptr< QgsFeatureSink > sink( parameterAsSink( parameters, QStringLiteral( 
"OUTPUT" ), context, dest, input->fields(), input->wkbType(), input->sourceCrs() ) );
   354   auto addToSink = [&]( 
const QgsFeature & feature )
   359   process( context, input.get(), intersectSource.get(), selectedPredicates, addToSink, 
false, feedback );
   362   results.insert( QStringLiteral( 
"OUTPUT" ), dest );
 QgsFeatureRequest & setDestinationCrs(const QgsCoordinateReferenceSystem &crs, const QgsCoordinateTransformContext &context)
Sets the destination crs for feature's geometries. 
 
Wrapper for iterator of features from vector data provider or vector layer. 
 
Use faster inserts, at the cost of updating the passed features to reflect changes made at the provid...
 
A rectangle specified with double values. 
 
Base class for providing feedback from a processing algorithm. 
 
QSet< QgsFeatureId > QgsFeatureIds
 
void setProgress(double progress)
Sets the current progress for the feedback object. 
 
QgsFeatureRequest & setSubsetOfAttributes(const QgsAttributeList &attrs)
Set a subset of attributes that will be fetched. 
 
virtual Flags flags() const
Returns the flags indicating how and when the algorithm operates and should be exposed to users...
 
void selectByIds(const QgsFeatureIds &ids, SelectBehavior behavior=SetSelection)
Select matching features using a list of feature IDs. 
 
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
 
bool hasGeometry() const
Returns true if the feature has an associated geometry. 
 
A feature sink output for processing algorithms. 
 
Base class for feedback objects to be used for cancelation of something running in a worker thread...
 
An enum based parameter for processing algorithms, allowing for selection from predefined values...
 
Algorithm is not thread safe and cannot be run in a background thread, e.g. for algorithms which mani...
 
This class wraps a request for features to a vector layer (or directly its vector data provider)...
 
Custom exception class for processing related exceptions. 
 
QgsFeatureRequest & setFilterRect(const QgsRectangle &rectangle)
Sets the rectangle from which features will be taken. 
 
QgsCoordinateTransformContext transformContext() const
Returns the coordinate transform context. 
 
A vector layer (with or without geometry) parameter for processing algorithms. 
 
QgsGeometry geometry() const
Returns the geometry associated with this feature. 
 
virtual QgsCoordinateReferenceSystem sourceCrs() const =0
Returns the coordinate reference system for features in the source. 
 
static QgsGeometryEngine * createGeometryEngine(const QgsAbstractGeometry *geometry)
Creates and returns a new geometry engine. 
 
const QgsAbstractGeometry * constGet() const
Returns a non-modifiable (const) reference to the underlying abstract geometry primitive. 
 
SelectBehavior
Selection behavior. 
 
QgsFeatureRequest & setFilterFids(const QgsFeatureIds &fids)
Set feature IDs that should be fetched. 
 
bool isCanceled() const
Tells whether the operation has been canceled already. 
 
An interface for objects which provide features via a getFeatures method. 
 
An input feature source (such as vector layers) parameter for processing algorithms. 
 
QgsRectangle boundingBox() const
Returns the bounding box of the geometry. 
 
QList< int > QgsAttributeList
 
bool nextFeature(QgsFeature &f)
 
Geometry is not required. It may still be returned if e.g. required for a filter condition. 
 
Represents a vector layer which manages a vector based data sets. 
 
virtual QgsFeatureIds allFeatureIds() const
Returns a list of all feature IDs for features present in the source. 
 
Contains information about the context in which a processing algorithm is executed. 
 
Any vector layer with geometry. 
 
virtual QgsFeatureIterator getFeatures(const QgsFeatureRequest &request=QgsFeatureRequest()) const =0
Returns an iterator for the features in the source. 
 
QgsFeatureRequest & setFlags(QgsFeatureRequest::Flags flags)
Set flags that affect how features will be fetched. 
 
virtual long featureCount() const =0
Returns the number of features contained in the source, or -1 if the feature count is unknown...