28QString QgsMultiIntersectionAlgorithm::name()
const
30 return QStringLiteral(
"multiintersection" );
33QString QgsMultiIntersectionAlgorithm::displayName()
const
35 return QObject::tr(
"Intersection (multiple)" );
38QStringList QgsMultiIntersectionAlgorithm::tags()
const
40 return QObject::tr(
"intersection,extract,overlap" ).split(
',' );
43QString QgsMultiIntersectionAlgorithm::group()
const
45 return QObject::tr(
"Vector overlay" );
48QString QgsMultiIntersectionAlgorithm::groupId()
const
50 return QStringLiteral(
"vectoroverlay" );
53QString QgsMultiIntersectionAlgorithm::shortHelpString()
const
55 return QObject::tr(
"This algorithm extracts the overlapping portions of features in the Input and all Overlay layers. "
56 "Features in the output layer are assigned the attributes of the overlapping features "
57 "from both the Input and Overlay layers." );
62 return new QgsMultiIntersectionAlgorithm();
65void QgsMultiIntersectionAlgorithm::initAlgorithm(
const QVariantMap & )
70 std::unique_ptr< QgsProcessingParameterString > prefix = std::make_unique< QgsProcessingParameterString >( QStringLiteral(
"OVERLAY_FIELDS_PREFIX" ), QObject::tr(
"Overlay fields prefix" ), QString(),
false,
true );
72 addParameter( prefix.release() );
79 std::unique_ptr< QgsFeatureSource > sourceA( parameterAsSource( parameters, QStringLiteral(
"INPUT" ), context ) );
83 const QList< QgsMapLayer * > layers = parameterAsLayerList( parameters, QStringLiteral(
"OVERLAYS" ), context );
86 long totalLayerCount = 0;
101 const QString overlayFieldsPrefix = parameterAsString( parameters, QStringLiteral(
"OVERLAY_FIELDS_PREFIX" ), context );
105 std::unique_ptr< QgsFeatureSink > sink;
109 QList<int> fieldIndicesA, fieldIndicesB;
112 if ( totalLayerCount == 1 )
114 QgsVectorLayer *overlayLayer = qobject_cast< QgsVectorLayer * >( layers.at( 0 ) );
122 overlayFieldsPrefix );
129 outputs.insert( QStringLiteral(
"OUTPUT" ), dest );
131 const long total = sourceA->featureCount();
132 QgsOverlayUtils::intersection( *sourceA, *overlayLayer, *sink, context, feedback, count, total, fieldIndicesA, fieldIndicesB );
145 multiStepFeedback.setCurrentStep( i );
150 QgsVectorLayer *overlayLayer = qobject_cast< QgsVectorLayer * >( layer );
163 overlayFieldsPrefix );
165 QString
id = QStringLiteral(
"memory:" );
167 QgsOverlayUtils::intersection( *sourceA, *overlayLayer, *sink, context, &multiStepFeedback, count, sourceA->featureCount(), fieldIndicesA, fieldIndicesB );
171 else if ( i == totalLayerCount - 1 )
179 overlayFieldsPrefix );
182 std::unique_ptr< QgsFeatureSink > sink( parameterAsSink( parameters, QStringLiteral(
"OUTPUT" ), context, dest, outputFields, geometryType,
crs ) );
186 outputs.insert( QStringLiteral(
"OUTPUT" ), dest );
188 QgsOverlayUtils::intersection( *intersectionLayer, *overlayLayer, *sink, context, &multiStepFeedback, count, intersectionLayer->
featureCount(), fieldIndicesA, fieldIndicesB );
198 overlayFieldsPrefix );
200 QString
id = QStringLiteral(
"memory:" );
202 QgsOverlayUtils::intersection( *intersectionLayer, *overlayLayer, *sink, context, &multiStepFeedback, count, intersectionLayer->
featureCount(), fieldIndicesA, fieldIndicesB );
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 SIP_HOLDGIL
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.
@ FlagAdvanced
Parameter is an advanced parameter which should be hidden from users by default.
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 QgsFeatureSink * createFeatureSink(QString &destination, QgsProcessingContext &context, const QgsFields &fields, QgsWkbTypes::Type 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 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 QgsMapLayer * mapLayerFromString(const QString &string, QgsProcessingContext &context, bool allowLoadingNewLayers=true, QgsProcessingUtils::LayerHint typeHint=QgsProcessingUtils::LayerHint::UnknownType)
Interprets a string as a map layer within the supplied context.
@ TypeVectorAnyGeometry
Any vector layer with geometry.
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.
QgsFields fields() const FINAL
Returns the list of fields of this layer.
Type
The WKB type describes the number of dimensions a geometry has.
static Type multiType(Type type) SIP_HOLDGIL
Returns the multi type for a WKB type.
@ VectorLayer
Vector layer.
const QgsCoordinateReferenceSystem & crs