25using namespace Qt::StringLiterals;
30QString QgsMultiIntersectionAlgorithm::name()
const
32 return u
"multiintersection"_s;
35QString QgsMultiIntersectionAlgorithm::displayName()
const
37 return QObject::tr(
"Intersection (multiple)" );
40QStringList QgsMultiIntersectionAlgorithm::tags()
const
42 return QObject::tr(
"intersection,extract,overlap" ).split(
',' );
45QString QgsMultiIntersectionAlgorithm::group()
const
47 return QObject::tr(
"Vector overlay" );
50QString QgsMultiIntersectionAlgorithm::groupId()
const
52 return u
"vectoroverlay"_s;
55QString QgsMultiIntersectionAlgorithm::shortHelpString()
const
57 return QObject::tr(
"This algorithm extracts the overlapping portions of features in the Input and all Overlay layers. "
58 "Features in the output layer are assigned the attributes of the overlapping features "
59 "from both the Input and Overlay layers." );
62QString QgsMultiIntersectionAlgorithm::shortDescription()
const
64 return QObject::tr(
"Extracts portions of input features that overlap features from all other layers." );
74 return new QgsMultiIntersectionAlgorithm();
77void QgsMultiIntersectionAlgorithm::initAlgorithm(
const QVariantMap & )
82 auto prefix = std::make_unique<QgsProcessingParameterString>( u
"OVERLAY_FIELDS_PREFIX"_s, QObject::tr(
"Overlay fields prefix" ), QString(),
false,
true );
84 addParameter( prefix.release() );
91 std::unique_ptr<QgsFeatureSource> sourceA( parameterAsSource( parameters, u
"INPUT"_s, context ) );
95 const QList<QgsMapLayer *> layers = parameterAsLayerList( parameters, u
"OVERLAYS"_s, context );
98 long totalLayerCount = 0;
113 const QString overlayFieldsPrefix = parameterAsString( parameters, u
"OVERLAY_FIELDS_PREFIX"_s, context );
117 std::unique_ptr<QgsFeatureSink> sink;
121 QList<int> fieldIndicesA, fieldIndicesB;
124 if ( totalLayerCount == 1 )
126 QgsVectorLayer *overlayLayer = qobject_cast<QgsVectorLayer *>( layers.at( 0 ) );
142 outputs.insert( u
"OUTPUT"_s, dest );
144 const long total = sourceA->featureCount();
145 QgsOverlayUtils::intersection( *sourceA, *overlayLayer, *sink, context, feedback, count, total, fieldIndicesA, fieldIndicesB );
160 multiStepFeedback.setCurrentStep( i );
165 QgsVectorLayer *overlayLayer = qobject_cast<QgsVectorLayer *>( layer );
181 QString
id = u
"memory:"_s;
183 QgsOverlayUtils::intersection( *sourceA, *overlayLayer, *sink, context, &multiStepFeedback, count, sourceA->featureCount(), fieldIndicesA, fieldIndicesB );
187 else if ( i == totalLayerCount - 1 )
199 std::unique_ptr<QgsFeatureSink> sink( parameterAsSink( parameters, u
"OUTPUT"_s, context, dest, outputFields, geometryType, crs ) );
203 outputs.insert( u
"OUTPUT"_s, dest );
205 QgsOverlayUtils::intersection( *intersectionLayer, *overlayLayer, *sink, context, &multiStepFeedback, count, intersectionLayer->
featureCount(), fieldIndicesA, fieldIndicesB );
218 QString
id = u
"memory:"_s;
220 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.
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 dataset.
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.