24void QgsDistanceWithinAlgorithm::addDistanceParameter()
 
   26  auto distanceParam = std::make_unique<QgsProcessingParameterDistance>( QStringLiteral( 
"DISTANCE" ), QObject::tr( 
"Where the features are within" ), 100, QStringLiteral( 
"INPUT" ), 
false, 0 );
 
   27  distanceParam->setIsDynamic( 
true );
 
   29  distanceParam->setDynamicLayerParameterName( QStringLiteral( 
"INPUT" ) );
 
   31  addParameter( distanceParam.release() );
 
   42  bool iterateOverTarget = 
false;
 
   52      iterateOverTarget = 
true;
 
   59      iterateOverTarget = 
true;
 
   67      iterateOverTarget = 
true;
 
   75      iterateOverTarget = 
true;
 
   80  if ( iterateOverTarget )
 
   82    processByIteratingOverTargetSource( context, targetSource, referenceSource, distance, distanceProperty, handleFeatureFunction, onlyRequireTargetIds, feedback, expressionContext );
 
   86    processByIteratingOverReferenceSource( context, targetSource, referenceSource, distance, handleFeatureFunction, onlyRequireTargetIds, feedback );
 
   93    feedback->
pushWarning( QObject::tr( 
"No spatial index exists for intersect layer, performance will be severely degraded" ) );
 
   97  if ( onlyRequireTargetIds )
 
  100  const bool dynamicDistance = distanceProperty.
isActive();
 
  115    double currentDistance = distance;
 
  116    if ( dynamicDistance )
 
  119      currentDistance = distanceProperty.
valueAsDouble( expressionContext, currentDistance );
 
  130      foundSet.insert( f.
id() );
 
  131      handleFeatureFunction( f );
 
  142    feedback->
pushWarning( QObject::tr( 
"No spatial index exists for input layer, performance will be severely degraded" ) );
 
  160    if ( onlyRequireTargetIds )
 
  170      if ( foundSet.contains( testFeature.
id() ) )
 
  176      foundSet.insert( testFeature.
id() );
 
  177      handleFeatureFunction( testFeature );
 
  190void QgsSelectWithinDistanceAlgorithm::initAlgorithm( 
const QVariantMap & )
 
  192  const QStringList methods = QStringList() << QObject::tr( 
"creating new selection" )
 
  193                                            << QObject::tr( 
"adding to current selection" )
 
  194                                            << QObject::tr( 
"selecting within current selection" )
 
  195                                            << QObject::tr( 
"removing from current selection" );
 
  200  addDistanceParameter();
 
  202  addParameter( 
new QgsProcessingParameterEnum( QStringLiteral( 
"METHOD" ), QObject::tr( 
"Modify current selection by" ), methods, 
false, 0 ) );
 
  205QString QgsSelectWithinDistanceAlgorithm::name()
 const 
  207  return QStringLiteral( 
"selectwithindistance" );
 
  215QString QgsSelectWithinDistanceAlgorithm::displayName()
 const 
  217  return QObject::tr( 
"Select within distance" );
 
  220QStringList QgsSelectWithinDistanceAlgorithm::tags()
 const 
  222  return QObject::tr( 
"select,by,maximum,buffer" ).split( 
',' );
 
  225QString QgsSelectWithinDistanceAlgorithm::group()
 const 
  227  return QObject::tr( 
"Vector selection" );
 
  230QString QgsSelectWithinDistanceAlgorithm::groupId()
 const 
  232  return QStringLiteral( 
"vectorselection" );
 
  235QString QgsSelectWithinDistanceAlgorithm::shortHelpString()
 const 
  237  return QObject::tr( 
"This algorithm creates a selection in a vector layer. Features are selected wherever they are within " 
  238                      "the specified maximum distance from the features in an additional reference layer." );
 
  241QString QgsSelectWithinDistanceAlgorithm::shortDescription()
 const 
  243  return QObject::tr( 
"Selects features that are within a specified distance from features in another layer." );
 
  246QgsSelectWithinDistanceAlgorithm *QgsSelectWithinDistanceAlgorithm::createInstance()
 const 
  248  return new QgsSelectWithinDistanceAlgorithm();
 
  253  QgsVectorLayer *selectLayer = parameterAsVectorLayer( parameters, QStringLiteral( 
"INPUT" ), context );
 
  258  const std::unique_ptr<QgsFeatureSource> referenceSource( parameterAsSource( parameters, QStringLiteral( 
"REFERENCE" ), context ) );
 
  259  if ( !referenceSource )
 
  262  const double distance = parameterAsDouble( parameters, QStringLiteral( 
"DISTANCE" ), context );
 
  265  if ( dynamicDistance )
 
  266    distanceProperty = parameters.
value( QStringLiteral( 
"DISTANCE" ) ).value<
QgsProperty>();
 
  271  auto addToSelection = [&]( 
const QgsFeature &feature ) {
 
  272    selectedIds.insert( feature.id() );
 
  274  process( context, selectLayer, referenceSource.get(), distance, distanceProperty, addToSelection, 
true, feedback, expressionContext );
 
  278  results.insert( QStringLiteral( 
"OUTPUT" ), parameters.value( QStringLiteral( 
"INPUT" ) ) );
 
  287void QgsExtractWithinDistanceAlgorithm::initAlgorithm( 
const QVariantMap & )
 
  291  addDistanceParameter();
 
  296QString QgsExtractWithinDistanceAlgorithm::name()
 const 
  298  return QStringLiteral( 
"extractwithindistance" );
 
  301QString QgsExtractWithinDistanceAlgorithm::displayName()
 const 
  303  return QObject::tr( 
"Extract within distance" );
 
  306QStringList QgsExtractWithinDistanceAlgorithm::tags()
 const 
  308  return QObject::tr( 
"extract,by,filter,select,maximum,buffer" ).split( 
',' );
 
  311QString QgsExtractWithinDistanceAlgorithm::group()
 const 
  313  return QObject::tr( 
"Vector selection" );
 
  316QString QgsExtractWithinDistanceAlgorithm::groupId()
 const 
  318  return QStringLiteral( 
"vectorselection" );
 
  321QString QgsExtractWithinDistanceAlgorithm::shortHelpString()
 const 
  323  return QObject::tr( 
"This algorithm creates a new vector layer that only contains matching features from an " 
  324                      "input layer. Features are copied wherever they are within " 
  325                      "the specified maximum distance from the features in an additional reference layer." );
 
  328QString QgsExtractWithinDistanceAlgorithm::shortDescription()
 const 
  330  return QObject::tr( 
"Creates a new vector layer with features that are within " 
  331                      "a specified distance from features in another layer." );
 
  334QgsExtractWithinDistanceAlgorithm *QgsExtractWithinDistanceAlgorithm::createInstance()
 const 
  336  return new QgsExtractWithinDistanceAlgorithm();
 
  341  std::unique_ptr<QgsProcessingFeatureSource> input( parameterAsSource( parameters, QStringLiteral( 
"INPUT" ), context ) );
 
  344  const std::unique_ptr<QgsFeatureSource> referenceSource( parameterAsSource( parameters, QStringLiteral( 
"REFERENCE" ), context ) );
 
  345  if ( !referenceSource )
 
  348  const double distance = parameterAsDouble( parameters, QStringLiteral( 
"DISTANCE" ), context );
 
  351  if ( dynamicDistance )
 
  352    distanceProperty = parameters.
value( QStringLiteral( 
"DISTANCE" ) ).value<
QgsProperty>();
 
  353  QgsExpressionContext expressionContext = createExpressionContext( parameters, context, input.get() );
 
  356  std::unique_ptr<QgsFeatureSink> sink( parameterAsSink( parameters, QStringLiteral( 
"OUTPUT" ), context, dest, input->fields(), input->wkbType(), input->sourceCrs() ) );
 
  361  auto addToSink = [&]( 
const QgsFeature &feature ) {
 
  366  process( context, input.get(), referenceSource.get(), distance, distanceProperty, addToSink, 
false, feedback, expressionContext );
 
  371  results.insert( QStringLiteral( 
"OUTPUT" ), dest );
 
@ VectorAnyGeometry
Any vector layer with geometry.
 
@ NotPresent
No spatial index exists for the source.
 
QFlags< ProcessingAlgorithmFlag > ProcessingAlgorithmFlags
Flags indicating how and when an algorithm operates and should be exposed to users.
 
@ NotAvailableInStandaloneTool
Algorithm should not be available from the standalone "qgis_process" tool. Used to flag algorithms wh...
 
@ NoThreading
Algorithm is not thread safe and cannot be run in a background thread, e.g. for algorithms which mani...
 
SelectBehavior
Specifies how a selection should be applied.
 
Represents a coordinate reference system (CRS).
 
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.
 
Wraps a request for features to a vector layer (or directly its vector data provider).
 
QgsFeatureRequest & setLimit(long long limit)
Set the maximum number of features to request.
 
QgsFeatureRequest & setDestinationCrs(const QgsCoordinateReferenceSystem &crs, const QgsCoordinateTransformContext &context)
Sets the destination crs for feature's geometries.
 
QgsFeatureRequest & setNoAttributes()
Set that no attributes will be fetched.
 
QgsFeatureRequest & setDistanceWithin(const QgsGeometry &geometry, double distance)
Sets a reference geometry and a maximum distance from this geometry to retrieve features within.
 
@ FastInsert
Use faster inserts, at the cost of updating the passed features to reflect changes made at the provid...
 
An interface for objects which provide features via a getFeatures method.
 
virtual QgsCoordinateReferenceSystem sourceCrs() const =0
Returns the coordinate reference system for features in the source.
 
virtual Qgis::WkbType wkbType() const =0
Returns the geometry type for features returned by this source.
 
virtual Qgis::SpatialIndexPresence hasSpatialIndex() const
Returns an enum value representing the presence of a valid spatial index on the source,...
 
virtual QgsFeatureIterator getFeatures(const QgsFeatureRequest &request=QgsFeatureRequest()) const =0
Returns an iterator for the features in the source.
 
virtual long long featureCount() const =0
Returns the number of features contained in the source, or -1 if the feature count is unknown.
 
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
 
bool hasGeometry() const
Returns true if the feature has an associated geometry.
 
bool isCanceled() const
Tells whether the operation has been canceled already.
 
void setProgress(double progress)
Sets the current progress for the feedback object.
 
virtual Qgis::ProcessingAlgorithmFlags flags() const
Returns the flags indicating how and when the algorithm operates and should be exposed to users.
 
Contains information about the context in which a processing algorithm is executed.
 
QgsCoordinateTransformContext transformContext() const
Returns the coordinate transform context.
 
Custom exception class for processing related exceptions.
 
Base class for providing feedback from a processing algorithm.
 
virtual void pushWarning(const QString &warning)
Pushes a warning informational message from the algorithm.
 
An enum based parameter for processing algorithms, allowing for selection from predefined values.
 
A feature sink output for processing algorithms.
 
An input feature source (such as vector layers) parameter for processing algorithms.
 
A vector layer (with or without geometry) parameter for processing algorithms.
 
static bool isDynamic(const QVariantMap ¶meters, const QString &name)
Returns true if the parameter with matching name is a dynamic parameter, and must be evaluated once f...
 
Definition for a property.
 
@ DoublePositive
Positive double value (including 0)
 
A store for object properties.
 
QVariant value(const QgsExpressionContext &context, const QVariant &defaultValue=QVariant(), bool *ok=nullptr) const
Calculates the current value of the property, including any transforms which are set for the property...
 
bool isActive() const
Returns whether the property is currently active.
 
double valueAsDouble(const QgsExpressionContext &context, double defaultValue=0.0, bool *ok=nullptr) const
Calculates the current value of the property and interprets it as a double.
 
Represents a vector layer which manages a vector based dataset.
 
QgsExpressionContextScope * createExpressionContextScope() const FINAL
This method needs to be reimplemented in all classes which implement this interface and return an exp...
 
Q_INVOKABLE void selectByIds(const QgsFeatureIds &ids, Qgis::SelectBehavior behavior=Qgis::SelectBehavior::SetSelection)
Selects matching features using a list of feature IDs.
 
QSet< QgsFeatureId > QgsFeatureIds