23 QString QgsUnionAlgorithm::name()
const 25 return QStringLiteral(
"union" );
28 QString QgsUnionAlgorithm::displayName()
const 30 return QObject::tr(
"Union" );
33 QString QgsUnionAlgorithm::group()
const 35 return QObject::tr(
"Vector overlay" );
38 QString QgsUnionAlgorithm::groupId()
const 40 return QStringLiteral(
"vectoroverlay" );
43 QString QgsUnionAlgorithm::shortHelpString()
const 45 return QObject::tr(
"This algorithm creates a layer containing all the features from both input layers. In the case of polygon layers, separate features are created for overlapping and non-overlapping features. The attribute table of the union layer contains attribute values from the respective input layer for non-overlapping features, and attribute values from both input layers for overlapping features." );
50 return new QgsUnionAlgorithm();
53 void QgsUnionAlgorithm::initAlgorithm(
const QVariantMap & )
63 std::unique_ptr< QgsFeatureSource > sourceA( parameterAsSource( parameters, QStringLiteral(
"INPUT" ), context ) );
67 std::unique_ptr< QgsFeatureSource > sourceB( parameterAsSource( parameters, QStringLiteral(
"OVERLAY" ), context ) );
68 if ( parameters.value( QStringLiteral(
"OVERLAY" ) ).isValid() && !sourceB )
76 std::unique_ptr< QgsFeatureSink > sink( parameterAsSink( parameters, QStringLiteral(
"OUTPUT" ), context, dest, fields, geomType, sourceA->sourceCrs() ) );
81 outputs.insert( QStringLiteral(
"OUTPUT" ), dest );
86 QgsOverlayUtils::resolveOverlaps( *sourceA.get(), *sink.get(), feedback );
94 int total = sourceA->featureCount() * 2 + sourceB->featureCount();
96 QgsOverlayUtils::intersection( *sourceA.get(), *sourceB.get(), *sink.get(), context, feedback, count, total, fieldIndicesA, fieldIndicesB );
98 QgsOverlayUtils::difference( *sourceA.get(), *sourceB.get(), *sink.get(), context, feedback, count, total, QgsOverlayUtils::OutputAB );
100 QgsOverlayUtils::difference( *sourceB.get(), *sourceA.get(), *sink.get(), context, feedback, count, total, QgsOverlayUtils::OutputBA );
static Type multiType(Type type)
Returns the multi type for a WKB type.
Base class for providing feedback from a processing algorithm.
Container of fields for a vector layer.
Abstract base class for processing algorithms.
A feature sink output for processing algorithms.
static QList< int > fieldNamesToIndices(const QStringList &fieldNames, const QgsFields &fields)
Returns a list of field indices parsed from the given list of field names.
Type
The WKB type describes the number of dimensions a geometry has.
static QgsFields combineFields(const QgsFields &fieldsA, const QgsFields &fieldsB)
Combines two field lists, avoiding duplicate field names (in a case-insensitive manner).
Custom exception class for processing related exceptions.
An input feature source (such as vector layers) parameter for processing algorithms.
Contains information about the context in which a processing algorithm is executed.