26QString QgsMultiUnionAlgorithm::name()
const
28 return QStringLiteral(
"multiunion" );
31QString QgsMultiUnionAlgorithm::displayName()
const
33 return QObject::tr(
"Union (multiple)" );
36QStringList QgsMultiUnionAlgorithm::tags()
const
38 return QObject::tr(
"union,overlap,not overlap" ).split(
',' );
41QString QgsMultiUnionAlgorithm::group()
const
43 return QObject::tr(
"Vector overlay" );
46QString QgsMultiUnionAlgorithm::groupId()
const
48 return QStringLiteral(
"vectoroverlay" );
51QString QgsMultiUnionAlgorithm::shortHelpString()
const
53 return QObject::tr(
"This algorithm checks overlaps between features within the Input layer and creates separate features for overlapping "
54 "and non-overlapping parts. The area of overlap will create as many identical overlapping features as there are "
55 "features that participate in that overlap." )
56 + QStringLiteral(
"\n\n" )
57 + QObject::tr(
"Multiple Overlay layers can also be used, in which case features from each layer are split at their overlap with features from "
58 "all other layers, creating a layer containing all the portions from both Input and Overlay layers. "
59 "The attribute table of the Union layer is filled with attribute values from the respective original layer "
60 "for non-overlapping features, and attribute values from both layers for overlapping features." );
70 return new QgsMultiUnionAlgorithm();
73void QgsMultiUnionAlgorithm::initAlgorithm(
const QVariantMap & )
78 std::unique_ptr< QgsProcessingParameterString > prefix = std::make_unique< QgsProcessingParameterString >( QStringLiteral(
"OVERLAY_FIELDS_PREFIX" ), QObject::tr(
"Overlay fields prefix" ), QString(),
false,
true );
80 addParameter( prefix.release() );
87 std::unique_ptr< QgsFeatureSource > sourceA( parameterAsSource( parameters, QStringLiteral(
"INPUT" ), context ) );
91 const QList< QgsMapLayer * > layers = parameterAsLayerList( parameters, QStringLiteral(
"OVERLAYS" ), context );
94 long totalLayerCount = 0;
111 const QString overlayFieldsPrefix = parameterAsString( parameters, QStringLiteral(
"OVERLAY_FIELDS_PREFIX" ), context );
112 std::unique_ptr< QgsFeatureSink > sink;
116 if ( totalLayerCount == 0 )
120 std::unique_ptr< QgsFeatureSink > sink( parameterAsSink( parameters, QStringLiteral(
"OUTPUT" ), context, dest, sourceA->fields(), geometryType, sourceA->sourceCrs(),
QgsFeatureSink::RegeneratePrimaryKey ) );
124 outputs.insert( QStringLiteral(
"OUTPUT" ), dest );
126 QgsOverlayUtils::resolveOverlaps( *sourceA, *sink, feedback );
142 multiStepFeedback.setCurrentStep( i );
147 QgsVectorLayer *overlayLayer = qobject_cast< QgsVectorLayer * >( layer );
153 QString
id = QStringLiteral(
"memory:" );
156 ok = makeUnion( *sourceA, *overlayLayer, *sink, context, &multiStepFeedback );
163 else if ( i == totalLayerCount - 1 )
173 outputs.insert( QStringLiteral(
"OUTPUT" ), dest );
174 ok = makeUnion( *unionLayer, *overlayLayer, *sink, context, &multiStepFeedback );
180 QString
id = QStringLiteral(
"memory:" );
183 ok = makeUnion( *unionLayer, *overlayLayer, *sink, context, &multiStepFeedback );
205 QgsOverlayUtils::intersection( sourceA, sourceB, sink, context, feedback, count, total, fieldIndicesA, fieldIndicesB );
209 QgsOverlayUtils::difference( sourceA, sourceB, sink, context, feedback, count, total, QgsOverlayUtils::OutputAB );
213 QgsOverlayUtils::difference( sourceB, sourceA, sink, context, feedback, count, total, QgsOverlayUtils::OutputBA );
@ 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).
An interface for objects which accept features via addFeature(s) methods.
@ RegeneratePrimaryKey
This flag indicates, that a primary key field cannot be guaranteed to be unique and the sink should i...
An interface for objects which provide features via a getFeatures method.
virtual QgsFields fields() const =0
Returns the fields associated with 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.
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 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.
static Qgis::WkbType multiType(Qgis::WkbType type)
Returns the multi type for a WKB type.
const QgsCoordinateReferenceSystem & crs