26QString QgsMultiDifferenceAlgorithm::name()
const
28 return QStringLiteral(
"multidifference" );
31QString QgsMultiDifferenceAlgorithm::displayName()
const
33 return QObject::tr(
"Difference (multiple)" );
36QStringList QgsMultiDifferenceAlgorithm::tags()
const
38 return QObject::tr(
"difference,erase,not overlap" ).split(
',' );
41QString QgsMultiDifferenceAlgorithm::group()
const
43 return QObject::tr(
"Vector overlay" );
46QString QgsMultiDifferenceAlgorithm::groupId()
const
48 return QStringLiteral(
"vectoroverlay" );
51QString QgsMultiDifferenceAlgorithm::shortHelpString()
const
53 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). "
54 "For each overlay layer the difference is calculated between the result of all previous difference operations and this overlay layer. "
55 "Input layer features that partially overlap feature(s) in the Overlay layers are split along those features' boundary "
56 "and only the portions outside the Overlay layer features are retained." )
57 + QStringLiteral(
"\n\n" )
58 + QObject::tr(
"Attributes are not modified, although properties such as area or length of the features will "
59 "be modified by the difference operation. If such properties are stored as attributes, those attributes will have to "
60 "be manually updated." );
65 return new QgsMultiDifferenceAlgorithm();
68void QgsMultiDifferenceAlgorithm::initAlgorithm(
const QVariantMap & )
78 std::unique_ptr< QgsFeatureSource > sourceA( parameterAsSource( parameters, QStringLiteral(
"INPUT" ), context ) );
82 const QList< QgsMapLayer * > layers = parameterAsLayerList( parameters, QStringLiteral(
"OVERLAYS" ), context );
85 long totalLayerCount = 0;
102 std::unique_ptr< QgsFeatureSink > sink;
106 if ( totalLayerCount == 1 )
109 sink.reset( parameterAsSink( parameters, QStringLiteral(
"OUTPUT" ), context, dest, sourceA->fields(), geometryType,
crs ) );
113 outputs.insert( QStringLiteral(
"OUTPUT" ), dest );
115 QgsVectorLayer *overlayLayer = qobject_cast< QgsVectorLayer * >( layers.at( 0 ) );
117 const long total = sourceA->featureCount();
118 QgsOverlayUtils::difference( *sourceA, *overlayLayer, *sink, context, feedback, count, total, QgsOverlayUtils::OutputA );
131 multiStepFeedback.setCurrentStep( i );
136 QgsVectorLayer *overlayLayer = qobject_cast< QgsVectorLayer * >( layer );
143 QString
id = QStringLiteral(
"memory:" );
145 QgsOverlayUtils::difference( *sourceA, *overlayLayer, *sink, context, &multiStepFeedback, count, sourceA->featureCount(), QgsOverlayUtils::OutputA );
149 else if ( i == totalLayerCount - 1 )
152 std::unique_ptr< QgsFeatureSink > sink( parameterAsSink( parameters, QStringLiteral(
"OUTPUT" ), context, dest, differenceLayer->
fields(), geometryType,
crs ) );
156 outputs.insert( QStringLiteral(
"OUTPUT" ), dest );
158 QgsOverlayUtils::difference( *differenceLayer, *overlayLayer, *sink, context, &multiStepFeedback, count, differenceLayer->
featureCount(), QgsOverlayUtils::OutputA );
162 QString
id = QStringLiteral(
"memory:" );
164 QgsOverlayUtils::difference( *differenceLayer, *overlayLayer, *sink, context, &multiStepFeedback, count, differenceLayer->
featureCount(), QgsOverlayUtils::OutputA );
This class represents a coordinate reference system (CRS).
bool isCanceled() const SIP_HOLDGIL
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, QgsWkbTypes::Type 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)
Interprets a string as a map layer within the supplied context.
@ TypeVectorAnyGeometry
Any vector layer with geometry.
Represents a vector layer which manages a vector based data sets.
long long featureCount(const QString &legendKey) const
Number of features rendered with specified legend key.
QgsFields fields() const FINAL
Returns the list of fields of this layer.
Type
The WKB type describes the number of dimensions a geometry has.
static Type multiType(Type type) SIP_HOLDGIL
Returns the multi type for a WKB type.
@ VectorLayer
Vector layer.
const QgsCoordinateReferenceSystem & crs