22using namespace Qt::StringLiterals;
26QString QgsSymmetricalDifferenceAlgorithm::name()
const
28 return u
"symmetricaldifference"_s;
31QString QgsSymmetricalDifferenceAlgorithm::displayName()
const
33 return QObject::tr(
"Symmetrical difference" );
36QStringList QgsSymmetricalDifferenceAlgorithm::tags()
const
38 return QObject::tr(
"difference,symdiff,not overlap" ).split(
',' );
41QString QgsSymmetricalDifferenceAlgorithm::group()
const
43 return QObject::tr(
"Vector overlay" );
46QString QgsSymmetricalDifferenceAlgorithm::groupId()
const
48 return u
"vectoroverlay"_s;
51QString QgsSymmetricalDifferenceAlgorithm::shortHelpString()
const
53 return QObject::tr(
"This algorithm extracts the portions of features from both the Input and Overlay layers that do not overlap. "
54 "Overlapping areas between the two layers are removed. The attribute table of the Symmetrical Difference layer "
55 "contains original attributes from both the Input and Overlay layers." );
58QString QgsSymmetricalDifferenceAlgorithm::shortDescription()
const
60 return QObject::tr(
"Extracts the portions of features from two layers that do not overlap." );
70 return new QgsSymmetricalDifferenceAlgorithm();
73void QgsSymmetricalDifferenceAlgorithm::initAlgorithm(
const QVariantMap & )
78 auto prefix = std::make_unique<QgsProcessingParameterString>( u
"OVERLAY_FIELDS_PREFIX"_s, QObject::tr(
"Overlay fields prefix" ), QString(),
false,
true );
80 addParameter( prefix.release() );
86 addParameter( gridSize.release() );
92 std::unique_ptr<QgsFeatureSource> sourceA( parameterAsSource( parameters, u
"INPUT"_s, context ) );
96 std::unique_ptr<QgsFeatureSource> sourceB( parameterAsSource( parameters, u
"OVERLAY"_s, context ) );
103 if ( geomTypeA != geomTypeB )
106 const QString overlayFieldsPrefix = parameterAsString( parameters, u
"OVERLAY_FIELDS_PREFIX"_s, context );
110 std::unique_ptr<QgsFeatureSink> sink( parameterAsSink( parameters, u
"OUTPUT"_s, context, dest, fields, geomTypeA, sourceA->sourceCrs(),
QgsFeatureSink::RegeneratePrimaryKey ) );
115 outputs.insert( u
"OUTPUT"_s, dest );
118 const long total = sourceA->featureCount() + sourceB->featureCount();
121 if ( parameters.value( u
"GRID_SIZE"_s ).isValid() )
123 geometryParameters.
setGridSize( parameterAsDouble( parameters, u
"GRID_SIZE"_s, context ) );
126 QgsOverlayUtils::difference( *sourceA, *sourceB, *sink, context, feedback, count, total, QgsOverlayUtils::OutputAB, geometryParameters, QgsOverlayUtils::SanitizeFlag::DontPromotePointGeometryToMultiPoint );
130 QgsOverlayUtils::difference( *sourceB, *sourceA, *sink, context, feedback, count, total, QgsOverlayUtils::OutputBA, geometryParameters, QgsOverlayUtils::SanitizeFlag::DontPromotePointGeometryToMultiPoint );
@ 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.
virtual void pushWarning(const QString &warning)
Pushes a warning informational message from the algorithm.
A feature sink output for processing algorithms.
An input feature source (such as vector layers) parameter for processing algorithms.
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 Q_INVOKABLE QString displayString(Qgis::WkbType type)
Returns a non-translated display string type for a WKB type, e.g., the geometry name used in WKT geom...
static Qgis::WkbType promoteNonPointTypesToMulti(Qgis::WkbType type)
Promotes a WKB geometry type to its multi-type equivalent, with the exception of point geometry types...