26QString QgsMultiIntersectionAlgorithm::name()
const
28 return QStringLiteral(
"multiintersection" );
31QString QgsMultiIntersectionAlgorithm::displayName()
const
33 return QObject::tr(
"Intersection (multiple)" );
36QStringList QgsMultiIntersectionAlgorithm::tags()
const
38 return QObject::tr(
"intersection,extract,overlap" ).split(
',' );
41QString QgsMultiIntersectionAlgorithm::group()
const
43 return QObject::tr(
"Vector overlay" );
46QString QgsMultiIntersectionAlgorithm::groupId()
const
48 return QStringLiteral(
"vectoroverlay" );
51QString QgsMultiIntersectionAlgorithm::shortHelpString()
const
53 return QObject::tr(
"This algorithm extracts the overlapping portions of features in the Input and all Overlay layers. "
54 "Features in the output layer are assigned the attributes of the overlapping features "
55 "from both the Input and Overlay layers." );
65 return new QgsMultiIntersectionAlgorithm();
68void QgsMultiIntersectionAlgorithm::initAlgorithm(
const QVariantMap & )
73 std::unique_ptr<QgsProcessingParameterString> prefix = std::make_unique<QgsProcessingParameterString>( QStringLiteral(
"OVERLAY_FIELDS_PREFIX" ), QObject::tr(
"Overlay fields prefix" ), QString(),
false,
true );
75 addParameter( prefix.release() );
82 std::unique_ptr<QgsFeatureSource> sourceA( parameterAsSource( parameters, QStringLiteral(
"INPUT" ), context ) );
86 const QList<QgsMapLayer *> layers = parameterAsLayerList( parameters, QStringLiteral(
"OVERLAYS" ), context );
89 long totalLayerCount = 0;
104 const QString overlayFieldsPrefix = parameterAsString( parameters, QStringLiteral(
"OVERLAY_FIELDS_PREFIX" ), context );
108 std::unique_ptr<QgsFeatureSink> sink;
112 QList<int> fieldIndicesA, fieldIndicesB;
115 if ( totalLayerCount == 1 )
117 QgsVectorLayer *overlayLayer = qobject_cast<QgsVectorLayer *>( layers.at( 0 ) );
133 outputs.insert( QStringLiteral(
"OUTPUT" ), dest );
135 const long total = sourceA->featureCount();
136 QgsOverlayUtils::intersection( *sourceA, *overlayLayer, *sink, context, feedback, count, total, fieldIndicesA, fieldIndicesB );
151 multiStepFeedback.setCurrentStep( i );
156 QgsVectorLayer *overlayLayer = qobject_cast<QgsVectorLayer *>( layer );
172 QString
id = QStringLiteral(
"memory:" );
174 QgsOverlayUtils::intersection( *sourceA, *overlayLayer, *sink, context, &multiStepFeedback, count, sourceA->featureCount(), fieldIndicesA, fieldIndicesB );
178 else if ( i == totalLayerCount - 1 )
190 std::unique_ptr<QgsFeatureSink> sink( parameterAsSink( parameters, QStringLiteral(
"OUTPUT" ), context, dest, outputFields, geometryType,
crs ) );
194 outputs.insert( QStringLiteral(
"OUTPUT" ), dest );
196 QgsOverlayUtils::intersection( *intersectionLayer, *overlayLayer, *sink, context, &multiStepFeedback, count, intersectionLayer->
featureCount(), fieldIndicesA, fieldIndicesB );
209 QString
id = QStringLiteral(
"memory:" );
211 QgsOverlayUtils::intersection( *intersectionLayer, *overlayLayer, *sink, context, &multiStepFeedback, count, intersectionLayer->
featureCount(), fieldIndicesA, fieldIndicesB );
@ VectorAnyGeometry
Any vector layer with geometry.
@ RegeneratesPrimaryKey
Algorithm always drops any existing primary keys or FID values and regenerates them in outputs.
QFlags< ProcessingAlgorithmDocumentationFlag > ProcessingAlgorithmDocumentationFlags
Flags describing algorithm behavior for documentation purposes.
WkbType
The WKB type describes the number of dimensions a geometry has.
@ Advanced
Parameter is an advanced parameter which should be hidden from users by default.
This class represents a coordinate reference system (CRS).
@ RegeneratePrimaryKey
This flag indicates, that a primary key field cannot be guaranteed to be unique and the sink should i...
bool isCanceled() const
Tells whether the operation has been canceled already.
Container of fields for a vector layer.
Base class for all map layer types.
Abstract base class for processing algorithms.
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.
Processing feedback object for multi-step operations.
A feature sink output for processing algorithms.
An input feature source (such as vector layers) parameter for processing algorithms.
A parameter for processing algorithms which accepts multiple map layers.
static QgsFields indicesToFields(const QList< int > &indices, const QgsFields &fields)
Returns a subset of fields based on the indices of desired fields.
static QList< int > fieldNamesToIndices(const QStringList &fieldNames, const QgsFields &fields)
Returns a list of field indices parsed from the given list of field names.
static QgsFields combineFields(const QgsFields &fieldsA, const QgsFields &fieldsB, const QString &fieldsBPrefix=QString())
Combines two field lists, avoiding duplicate field names (in a case-insensitive manner).
static QgsFeatureSink * createFeatureSink(QString &destination, QgsProcessingContext &context, const QgsFields &fields, Qgis::WkbType geometryType, const QgsCoordinateReferenceSystem &crs, const QVariantMap &createOptions=QVariantMap(), const QStringList &datasourceOptions=QStringList(), const QStringList &layerOptions=QStringList(), QgsFeatureSink::SinkFlags sinkFlags=QgsFeatureSink::SinkFlags(), QgsRemappingSinkDefinition *remappingDefinition=nullptr)
Creates a feature sink ready for adding features.
static QgsMapLayer * mapLayerFromString(const QString &string, QgsProcessingContext &context, bool allowLoadingNewLayers=true, QgsProcessingUtils::LayerHint typeHint=QgsProcessingUtils::LayerHint::UnknownType, QgsProcessing::LayerOptionsFlags flags=QgsProcessing::LayerOptionsFlags())
Interprets a string as a map layer within the supplied context.
Represents a vector layer which manages a vector based data sets.
long long featureCount(const QString &legendKey) const
Number of features rendered with specified legend key.
static Qgis::WkbType multiType(Qgis::WkbType type)
Returns the multi type for a WKB type.
const QgsCoordinateReferenceSystem & crs