22QString QgsSymmetricalDifferenceAlgorithm::name()
const
24 return QStringLiteral(
"symmetricaldifference" );
27QString QgsSymmetricalDifferenceAlgorithm::displayName()
const
29 return QObject::tr(
"Symmetrical difference" );
32QStringList QgsSymmetricalDifferenceAlgorithm::tags()
const
34 return QObject::tr(
"difference,symdiff,not overlap" ).split(
',' );
37QString QgsSymmetricalDifferenceAlgorithm::group()
const
39 return QObject::tr(
"Vector overlay" );
42QString QgsSymmetricalDifferenceAlgorithm::groupId()
const
44 return QStringLiteral(
"vectoroverlay" );
47QString QgsSymmetricalDifferenceAlgorithm::shortHelpString()
const
49 return QObject::tr(
"This algorithm extracts the portions of features from both the Input and Overlay layers that do not overlap. "
50 "Overlapping areas between the two layers are removed. The attribute table of the Symmetrical Difference layer "
51 "contains original attributes from both the Input and Difference layers." );
61 return new QgsSymmetricalDifferenceAlgorithm();
64void QgsSymmetricalDifferenceAlgorithm::initAlgorithm(
const QVariantMap & )
69 std::unique_ptr<QgsProcessingParameterString> prefix = std::make_unique<QgsProcessingParameterString>( QStringLiteral(
"OVERLAY_FIELDS_PREFIX" ), QObject::tr(
"Overlay fields prefix" ), QString(),
false,
true );
71 addParameter( prefix.release() );
75 std::unique_ptr<QgsProcessingParameterNumber> gridSize = std::make_unique<QgsProcessingParameterNumber>( QStringLiteral(
"GRID_SIZE" ), QObject::tr(
"Grid size" ),
Qgis::ProcessingNumberParameterType::Double, QVariant(),
true, 0 );
77 addParameter( gridSize.release() );
83 std::unique_ptr<QgsFeatureSource> sourceA( parameterAsSource( parameters, QStringLiteral(
"INPUT" ), context ) );
87 std::unique_ptr<QgsFeatureSource> sourceB( parameterAsSource( parameters, QStringLiteral(
"OVERLAY" ), context ) );
94 if ( geomTypeA != geomTypeB )
97 const QString overlayFieldsPrefix = parameterAsString( parameters, QStringLiteral(
"OVERLAY_FIELDS_PREFIX" ), context );
101 std::unique_ptr<QgsFeatureSink> sink( parameterAsSink( parameters, QStringLiteral(
"OUTPUT" ), context, dest, fields, geomTypeA, sourceA->sourceCrs(),
QgsFeatureSink::RegeneratePrimaryKey ) );
106 outputs.insert( QStringLiteral(
"OUTPUT" ), dest );
109 const long total = sourceA->featureCount() + sourceB->featureCount();
112 if ( parameters.value( QStringLiteral(
"GRID_SIZE" ) ).isValid() )
114 geometryParameters.
setGridSize( parameterAsDouble( parameters, QStringLiteral(
"GRID_SIZE" ), context ) );
117 QgsOverlayUtils::difference( *sourceA, *sourceB, *sink, context, feedback, count, total, QgsOverlayUtils::OutputAB, geometryParameters, QgsOverlayUtils::SanitizeFlag::DontPromotePointGeometryToMultiPoint );
121 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 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...