23QString QgsUnionAlgorithm::name()
const
25 return QStringLiteral(
"union" );
28QString QgsUnionAlgorithm::displayName()
const
30 return QObject::tr(
"Union" );
33QString QgsUnionAlgorithm::group()
const
35 return QObject::tr(
"Vector overlay" );
38QString QgsUnionAlgorithm::groupId()
const
40 return QStringLiteral(
"vectoroverlay" );
43QString QgsUnionAlgorithm::shortHelpString()
const
45 return QObject::tr(
"This algorithm checks overlaps between features within the Input layer and creates separate features for overlapping "
46 "and non-overlapping parts. The area of overlap will create as many identical overlapping features as there are "
47 "features that participate in that overlap." )
48 + QStringLiteral(
"\n\n" )
49 + QObject::tr(
"An Overlay layer can also be used, in which case features from each layer are split at their overlap with features from "
50 "the other one, creating a layer containing all the portions from both Input and Overlay layers. "
51 "The attribute table of the Union layer is filled with attribute values from the respective original layer "
52 "for non-overlapping features, and attribute values from both layers for overlapping features." );
62 return new QgsUnionAlgorithm();
65void QgsUnionAlgorithm::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() );
76 std::unique_ptr< QgsProcessingParameterNumber > gridSize = std::make_unique< QgsProcessingParameterNumber >( QStringLiteral(
"GRID_SIZE" ),
79 addParameter( gridSize.release() );
84 std::unique_ptr< QgsFeatureSource > sourceA( parameterAsSource( parameters, QStringLiteral(
"INPUT" ), context ) );
88 std::unique_ptr< QgsFeatureSource > sourceB( parameterAsSource( parameters, QStringLiteral(
"OVERLAY" ), context ) );
89 if ( parameters.value( QStringLiteral(
"OVERLAY" ) ).isValid() && !sourceB )
94 const QString overlayFieldsPrefix = parameterAsString( parameters, QStringLiteral(
"OVERLAY_FIELDS_PREFIX" ), context );
98 std::unique_ptr< QgsFeatureSink > sink( parameterAsSink( parameters, QStringLiteral(
"OUTPUT" ), context, dest, fields, geomType, sourceA->sourceCrs(),
QgsFeatureSink::RegeneratePrimaryKey ) );
103 outputs.insert( QStringLiteral(
"OUTPUT" ), dest );
108 QgsOverlayUtils::resolveOverlaps( *sourceA, *sink, feedback );
116 const long total = sourceA->featureCount() * 2 + sourceB->featureCount();
119 if ( parameters.value( QStringLiteral(
"GRID_SIZE" ) ).isValid() )
121 geometryParameters.
setGridSize( parameterAsDouble( parameters, QStringLiteral(
"GRID_SIZE" ), context ) );
124 QgsOverlayUtils::intersection( *sourceA, *sourceB, *sink, context, feedback, count, total, fieldIndicesA, fieldIndicesB, geometryParameters );
128 QgsOverlayUtils::difference( *sourceA, *sourceB, *sink, context, feedback, count, total, QgsOverlayUtils::OutputAB, geometryParameters );
132 QgsOverlayUtils::difference( *sourceB, *sourceA, *sink, context, feedback, count, total, QgsOverlayUtils::OutputBA, geometryParameters );
@ 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.
@ Double
Double/float values.
@ 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.
Encapsulates parameters under which a geometry operation is performed.
void setGridSize(double size)
Sets the grid size which will be used to snap vertices of a geometry.
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.
A feature sink output for processing algorithms.
An input feature source (such as vector layers) parameter 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.
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 Qgis::WkbType multiType(Qgis::WkbType type)
Returns the multi type for a WKB type.