26 QString QgsMultiUnionAlgorithm::name()
const
28 return QStringLiteral(
"multiunion" );
31 QString QgsMultiUnionAlgorithm::displayName()
const
33 return QObject::tr(
"Union (multiple)" );
36 QStringList QgsMultiUnionAlgorithm::tags()
const
38 return QObject::tr(
"union,overlap,not overlap" ).split(
',' );
41 QString QgsMultiUnionAlgorithm::group()
const
43 return QObject::tr(
"Vector overlay" );
46 QString QgsMultiUnionAlgorithm::groupId()
const
48 return QStringLiteral(
"vectoroverlay" );
51 QString 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." );
65 return new QgsMultiUnionAlgorithm();
68 void QgsMultiUnionAlgorithm::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;
106 const QString overlayFieldsPrefix = parameterAsString( parameters, QStringLiteral(
"OVERLAY_FIELDS_PREFIX" ), context );
107 std::unique_ptr< QgsFeatureSink > sink;
111 if ( totalLayerCount == 0 )
115 std::unique_ptr< QgsFeatureSink > sink( parameterAsSink( parameters, QStringLiteral(
"OUTPUT" ), context, dest, sourceA->fields(), geometryType, sourceA->sourceCrs(),
QgsFeatureSink::RegeneratePrimaryKey ) );
119 outputs.insert( QStringLiteral(
"OUTPUT" ), dest );
121 QgsOverlayUtils::resolveOverlaps( *sourceA, *sink, feedback );
136 multiStepFeedback.setCurrentStep( i );
141 QgsVectorLayer *overlayLayer = qobject_cast< QgsVectorLayer * >( layer );
147 QString
id = QStringLiteral(
"memory:" );
150 ok = makeUnion( *sourceA, *overlayLayer, *sink, context, &multiStepFeedback );
157 else if ( i == totalLayerCount - 1 )
167 outputs.insert( QStringLiteral(
"OUTPUT" ), dest );
168 ok = makeUnion( *unionLayer, *overlayLayer, *sink, context, &multiStepFeedback );
174 QString
id = QStringLiteral(
"memory:" );
177 ok = makeUnion( *unionLayer, *overlayLayer, *sink, context, &multiStepFeedback );
199 QgsOverlayUtils::intersection( sourceA, sourceB, sink, context, feedback, count, total, fieldIndicesA, fieldIndicesB );
203 QgsOverlayUtils::difference( sourceA, sourceB, sink, context, feedback, count, total, QgsOverlayUtils::OutputAB );
207 QgsOverlayUtils::difference( sourceB, sourceA, sink, context, feedback, count, total, QgsOverlayUtils::OutputBA );