25using namespace Qt::StringLiterals;
30QString QgsMultiDifferenceAlgorithm::name()
const
32 return u
"multidifference"_s;
35QString QgsMultiDifferenceAlgorithm::displayName()
const
37 return QObject::tr(
"Difference (multiple)" );
40QStringList QgsMultiDifferenceAlgorithm::tags()
const
42 return QObject::tr(
"difference,erase,not overlap" ).split(
',' );
45QString QgsMultiDifferenceAlgorithm::group()
const
47 return QObject::tr(
"Vector overlay" );
50QString QgsMultiDifferenceAlgorithm::groupId()
const
52 return u
"vectoroverlay"_s;
55QString QgsMultiDifferenceAlgorithm::shortHelpString()
const
57 return QObject::tr(
"This algorithm extracts features from the Input layer that fall completely outside or only partially overlap the features from any of the Overlay layer(s). "
58 "For each overlay layer the difference is calculated between the result of all previous difference operations and this overlay layer. "
59 "Input layer features that partially overlap feature(s) in the Overlay layers are split along those features' boundary "
60 "and only the portions outside the Overlay layer features are retained." )
62 + QObject::tr(
"Attributes are not modified, although properties such as area or length of the features will "
63 "be modified by the difference operation. If such properties are stored as attributes, those attributes will have to "
64 "be manually updated." );
67QString QgsMultiDifferenceAlgorithm::shortDescription()
const
69 return QObject::tr(
"Extracts features from a layer that fall completely outside or only partially overlap the features from other layer(s)." );
74 return new QgsMultiDifferenceAlgorithm();
77void QgsMultiDifferenceAlgorithm::initAlgorithm(
const QVariantMap & )
87 std::unique_ptr<QgsFeatureSource> sourceA( parameterAsSource( parameters, u
"INPUT"_s, context ) );
91 const QList<QgsMapLayer *> layers = parameterAsLayerList( parameters, u
"OVERLAYS"_s, context );
94 long totalLayerCount = 0;
111 std::unique_ptr<QgsFeatureSink> sink;
115 if ( totalLayerCount == 1 )
118 sink.reset( parameterAsSink( parameters, u
"OUTPUT"_s, context, dest, sourceA->fields(), geometryType, crs ) );
122 outputs.insert( u
"OUTPUT"_s, dest );
124 QgsVectorLayer *overlayLayer = qobject_cast<QgsVectorLayer *>( layers.at( 0 ) );
126 const long total = sourceA->featureCount();
127 QgsOverlayUtils::difference( *sourceA, *overlayLayer, *sink, context, feedback, count, total, QgsOverlayUtils::OutputA );
141 multiStepFeedback.setCurrentStep( i );
146 QgsVectorLayer *overlayLayer = qobject_cast<QgsVectorLayer *>( layer );
153 QString
id = u
"memory:"_s;
155 QgsOverlayUtils::difference( *sourceA, *overlayLayer, *sink, context, &multiStepFeedback, count, sourceA->featureCount(), QgsOverlayUtils::OutputA );
159 else if ( i == totalLayerCount - 1 )
162 std::unique_ptr<QgsFeatureSink> sink( parameterAsSink( parameters, u
"OUTPUT"_s, context, dest, differenceLayer->
fields(), geometryType, crs ) );
166 outputs.insert( u
"OUTPUT"_s, dest );
168 QgsOverlayUtils::difference( *differenceLayer, *overlayLayer, *sink, context, &multiStepFeedback, count, differenceLayer->
featureCount(), QgsOverlayUtils::OutputA );
172 QString
id = u
"memory:"_s;
174 QgsOverlayUtils::difference( *differenceLayer, *overlayLayer, *sink, context, &multiStepFeedback, count, differenceLayer->
featureCount(), QgsOverlayUtils::OutputA );
@ VectorAnyGeometry
Any vector layer with geometry.
WkbType
The WKB type describes the number of dimensions a geometry has.
Represents a coordinate reference system (CRS).
bool isCanceled() const
Tells whether the operation has been canceled already.
Base class for all map layer types.
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.
Processing feedback object for multi-step operations.
A feature sink output for processing algorithms.
An input feature source (such as vector layers) parameter for processing algorithms.
A parameter for processing algorithms which accepts multiple map layers.
static QgsFeatureSink * createFeatureSink(QString &destination, QgsProcessingContext &context, const QgsFields &fields, Qgis::WkbType geometryType, const QgsCoordinateReferenceSystem &crs, const QVariantMap &createOptions=QVariantMap(), const QStringList &datasourceOptions=QStringList(), const QStringList &layerOptions=QStringList(), QgsFeatureSink::SinkFlags sinkFlags=QgsFeatureSink::SinkFlags(), QgsRemappingSinkDefinition *remappingDefinition=nullptr)
Creates a feature sink ready for adding features.
static QgsMapLayer * mapLayerFromString(const QString &string, QgsProcessingContext &context, bool allowLoadingNewLayers=true, QgsProcessingUtils::LayerHint typeHint=QgsProcessingUtils::LayerHint::UnknownType, QgsProcessing::LayerOptionsFlags flags=QgsProcessing::LayerOptionsFlags())
Interprets a string as a map layer within the supplied context.
Represents a vector layer which manages a vector based dataset.
long long featureCount(const QString &legendKey) const
Number of features rendered with specified legend key.
static Qgis::WkbType multiType(Qgis::WkbType type)
Returns the multi type for a WKB type.