25QString QgsClipAlgorithm::name()
const
27 return QStringLiteral(
"clip" );
30QgsProcessingAlgorithm::Flags QgsClipAlgorithm::flags()
const
37QString QgsClipAlgorithm::displayName()
const
39 return QObject::tr(
"Clip" );
42QStringList QgsClipAlgorithm::tags()
const
44 return QObject::tr(
"clip,intersect,intersection,mask" ).split(
',' );
47QString QgsClipAlgorithm::group()
const
49 return QObject::tr(
"Vector overlay" );
52QString QgsClipAlgorithm::groupId()
const
54 return QStringLiteral(
"vectoroverlay" );
57void QgsClipAlgorithm::initAlgorithm(
const QVariantMap & )
65QString QgsClipAlgorithm::shortHelpString()
const
67 return QObject::tr(
"This algorithm clips a vector layer using the features of an additional polygon layer. Only the parts of the features "
68 "in the Input layer that fall within the polygons of the Overlay layer will be added to the resulting layer." )
69 + QStringLiteral(
"\n\n" )
70 + QObject::tr(
"The attributes of the features are not modified, although properties such as area or length of the features will "
71 "be modified by the clipping operation. If such properties are stored as attributes, those attributes will have to "
72 "be manually updated." );
75QgsClipAlgorithm *QgsClipAlgorithm::createInstance()
const
77 return new QgsClipAlgorithm();
80bool QgsClipAlgorithm::supportInPlaceEdit(
const QgsMapLayer *l )
const
82 const QgsVectorLayer *layer = qobject_cast< const QgsVectorLayer * >( l );
91 std::unique_ptr< QgsFeatureSource > featureSource( parameterAsSource( parameters, QStringLiteral(
"INPUT" ), context ) );
95 std::unique_ptr< QgsFeatureSource > maskSource( parameterAsSource( parameters, QStringLiteral(
"OVERLAY" ), context ) );
100 feedback->
pushWarning( QObject::tr(
"No spatial index exists for input layer, performance will be severely degraded" ) );
104 std::unique_ptr< QgsFeatureSink > sink( parameterAsSink( parameters, QStringLiteral(
"OUTPUT" ), context, dest, featureSource->fields(),
QgsWkbTypes::promoteNonPointTypesToMulti( featureSource->wkbType() ), featureSource->sourceCrs() ) );
110 QVector< QgsGeometry > clipGeoms;
120 outputs.insert( QStringLiteral(
"OUTPUT" ), dest );
122 if ( clipGeoms.isEmpty() )
126 bool singleClipFeature =
false;
128 if ( clipGeoms.length() > 1 )
131 if ( combinedClipGeom.
isEmpty() )
135 singleClipFeature =
false;
139 combinedClipGeom = clipGeoms.at( 0 );
140 singleClipFeature =
true;
145 engine->prepareGeometry();
150 const auto constClipGeoms = clipGeoms;
151 for (
const QgsGeometry &clipGeom : constClipGeoms )
164 if ( inputFeatures.isEmpty() )
168 if ( singleClipFeature )
169 step = 100.0 / inputFeatures.length();
171 const int current = 0;
172 const auto constInputFeatures = inputFeatures;
173 for (
const QgsFeature &inputFeature : constInputFeatures )
180 if ( !inputFeature.hasGeometry() )
183 if ( testedFeatureIds.contains( inputFeature.id() ) )
188 testedFeatureIds.insert( inputFeature.id() );
190 if ( !engine->intersects( inputFeature.geometry().constGet() ) )
194 if ( !engine->contains( inputFeature.geometry().constGet() ) )
196 const QgsGeometry currentGeometry = inputFeature.geometry();
197 newGeometry = combinedClipGeom.
intersection( currentGeometry );
208 newGeometry = inputFeature.geometry();
211 if ( !QgsOverlayUtils::sanitizeIntersectionResult( newGeometry, sinkType, QgsOverlayUtils::SanitizeFlag::DontPromotePointGeometryToMultiPoint ) )
221 if ( singleClipFeature )
225 if ( !singleClipFeature )
228 feedback->
setProgress( 100.0 *
static_cast< double >( i ) / clipGeoms.length() );
Wrapper for iterator of features from vector data provider or vector layer.
bool nextFeature(QgsFeature &f)
This class wraps a request for features to a vector layer (or directly its vector data provider).
@ FastInsert
Use faster inserts, at the cost of updating the passed features to reflect changes made at the provid...
@ SpatialIndexNotPresent
No spatial index exists for the source.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
void setAttributes(const QgsAttributes &attrs)
Sets the feature's attributes.
bool hasGeometry() const
Returns true if the feature has an associated geometry.
void setGeometry(const QgsGeometry &geometry)
Set the feature's geometry.
bool isCanceled() const SIP_HOLDGIL
Tells whether the operation has been canceled already.
void setProgress(double progress)
Sets the current progress for the feedback object.
A geometry is the spatial representation of a feature.
const QgsAbstractGeometry * constGet() const SIP_HOLDGIL
Returns a non-modifiable (const) reference to the underlying abstract geometry primitive.
QgsGeometry difference(const QgsGeometry &geometry, const QgsGeometryParameters ¶meters=QgsGeometryParameters()) const
Returns a geometry representing the points making up this geometry that do not make up other.
QgsWkbTypes::Type wkbType() const SIP_HOLDGIL
Returns type of the geometry as a WKB type (point / linestring / polygon etc.)
QgsGeometry combine(const QgsGeometry &geometry, const QgsGeometryParameters ¶meters=QgsGeometryParameters()) const
Returns a geometry representing all the points in this geometry and other (a union geometry operation...
static QgsGeometryEngine * createGeometryEngine(const QgsAbstractGeometry *geometry)
Creates and returns a new geometry engine representing the specified geometry.
QString lastError() const SIP_HOLDGIL
Returns an error string referring to the last error encountered either when this geometry was created...
QgsGeometry intersection(const QgsGeometry &geometry, const QgsGeometryParameters ¶meters=QgsGeometryParameters()) const
Returns a geometry representing the points shared by this geometry and other.
QgsGeometry symDifference(const QgsGeometry &geometry, const QgsGeometryParameters ¶meters=QgsGeometryParameters()) const
Returns a geometry representing the points making up this geometry that do not make up other.
bool isEmpty() const
Returns true if the geometry is empty (eg a linestring with no vertices, or a collection with no geom...
static QgsGeometry unaryUnion(const QVector< QgsGeometry > &geometries, const QgsGeometryParameters ¶meters=QgsGeometryParameters())
Compute the unary union on a list of geometries.
Base class for all map layer types.
virtual Flags flags() const
Returns the flags indicating how and when the algorithm operates and should be exposed to users.
@ FlagSupportsInPlaceEdits
Algorithm supports in-place editing.
Contains information about the context in which a processing algorithm is executed.
QgsCoordinateTransformContext transformContext() const
Returns the coordinate transform context.
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.
@ TypeVectorPolygon
Vector polygon layers.
Represents a vector layer which manages a vector based data sets.
bool isSpatial() const FINAL
Returns true if this is a geometry layer and false in case of NoGeometry (table only) or UnknownGeome...
static GeometryType geometryType(Type type) SIP_HOLDGIL
Returns the geometry type for a WKB type, e.g., both MultiPolygon and CurvePolygon would have a Polyg...
static Type promoteNonPointTypesToMulti(Type type) SIP_HOLDGIL
Promotes a WKB geometry type to its multi-type equivalent, with the exception of point geometry types...
GeometryType
The geometry types are used to group QgsWkbTypes::Type in a coarse way.
static Type flatType(Type type) SIP_HOLDGIL
Returns the flat type for a WKB type.
QList< QgsFeature > QgsFeatureList
QSet< QgsFeatureId > QgsFeatureIds