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." );
60 return new QgsMultiIntersectionAlgorithm();
63void QgsMultiIntersectionAlgorithm::initAlgorithm(
const QVariantMap & )
68 std::unique_ptr< QgsProcessingParameterString > prefix = std::make_unique< QgsProcessingParameterString >( QStringLiteral(
"OVERLAY_FIELDS_PREFIX" ), QObject::tr(
"Overlay fields prefix" ), QString(),
false,
true );
70 addParameter( prefix.release() );
77 std::unique_ptr< QgsFeatureSource > sourceA( parameterAsSource( parameters, QStringLiteral(
"INPUT" ), context ) );
81 const QList< QgsMapLayer * > layers = parameterAsLayerList( parameters, QStringLiteral(
"OVERLAYS" ), context );
84 long totalLayerCount = 0;
99 const QString overlayFieldsPrefix = parameterAsString( parameters, QStringLiteral(
"OVERLAY_FIELDS_PREFIX" ), context );
103 std::unique_ptr< QgsFeatureSink > sink;
107 QList<int> fieldIndicesA, fieldIndicesB;
110 if ( totalLayerCount == 1 )
112 QgsVectorLayer *overlayLayer = qobject_cast< QgsVectorLayer * >( layers.at( 0 ) );
120 overlayFieldsPrefix );
127 outputs.insert( QStringLiteral(
"OUTPUT" ), dest );
129 const long total = sourceA->featureCount();
130 QgsOverlayUtils::intersection( *sourceA, *overlayLayer, *sink, context, feedback, count, total, fieldIndicesA, fieldIndicesB );
143 multiStepFeedback.setCurrentStep( i );
148 QgsVectorLayer *overlayLayer = qobject_cast< QgsVectorLayer * >( layer );
161 overlayFieldsPrefix );
163 QString
id = QStringLiteral(
"memory:" );
165 QgsOverlayUtils::intersection( *sourceA, *overlayLayer, *sink, context, &multiStepFeedback, count, sourceA->featureCount(), fieldIndicesA, fieldIndicesB );
169 else if ( i == totalLayerCount - 1 )
177 overlayFieldsPrefix );
180 std::unique_ptr< QgsFeatureSink > sink( parameterAsSink( parameters, QStringLiteral(
"OUTPUT" ), context, dest, outputFields, geometryType,
crs ) );
184 outputs.insert( QStringLiteral(
"OUTPUT" ), dest );
186 QgsOverlayUtils::intersection( *intersectionLayer, *overlayLayer, *sink, context, &multiStepFeedback, count, intersectionLayer->
featureCount(), fieldIndicesA, fieldIndicesB );
196 overlayFieldsPrefix );
198 QString
id = QStringLiteral(
"memory:" );
200 QgsOverlayUtils::intersection( *intersectionLayer, *overlayLayer, *sink, context, &multiStepFeedback, count, intersectionLayer->
featureCount(), fieldIndicesA, fieldIndicesB );
@ VectorAnyGeometry
Any vector layer with geometry.
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