25 QString QgsClipAlgorithm::name()
const 27 return QStringLiteral(
"clip" );
30 QgsProcessingAlgorithm::Flags QgsClipAlgorithm::flags()
const 37 QString QgsClipAlgorithm::displayName()
const 39 return QObject::tr(
"Clip" );
42 QStringList QgsClipAlgorithm::tags()
const 44 return QObject::tr(
"clip,intersect,intersection,mask" ).split(
',' );
47 QString QgsClipAlgorithm::group()
const 49 return QObject::tr(
"Vector overlay" );
52 QString QgsClipAlgorithm::groupId()
const 54 return QStringLiteral(
"vectoroverlay" );
57 void QgsClipAlgorithm::initAlgorithm(
const QVariantMap & )
65 QString 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." );
75 QgsClipAlgorithm *QgsClipAlgorithm::createInstance()
const 77 return new QgsClipAlgorithm();
80 bool QgsClipAlgorithm::supportInPlaceEdit(
const QgsMapLayer *l )
const 91 std::unique_ptr< QgsFeatureSource > featureSource( parameterAsSource( parameters, QStringLiteral(
"INPUT" ), context ) );
95 std::unique_ptr< QgsFeatureSource > maskSource( parameterAsSource( parameters, QStringLiteral(
"OVERLAY" ), context ) );
101 std::unique_ptr< QgsFeatureSink > sink( parameterAsSink( parameters, QStringLiteral(
"OUTPUT" ), context, dest, featureSource->fields(),
QgsWkbTypes::multiType( featureSource->wkbType() ), featureSource->sourceCrs() ) );
107 QVector< QgsGeometry > clipGeoms;
117 outputs.insert( QStringLiteral(
"OUTPUT" ), dest );
119 if ( clipGeoms.isEmpty() )
123 bool singleClipFeature =
false;
125 if ( clipGeoms.length() > 1 )
128 if ( combinedClipGeom.
isEmpty() )
132 singleClipFeature =
false;
136 combinedClipGeom = clipGeoms.at( 0 );
137 singleClipFeature =
true;
142 engine->prepareGeometry();
147 Q_FOREACH (
const QgsGeometry &clipGeom, clipGeoms )
160 if ( inputFeatures.isEmpty() )
164 if ( singleClipFeature )
165 step = 100.0 / inputFeatures.length();
168 Q_FOREACH (
const QgsFeature &inputFeature, inputFeatures )
178 if ( testedFeatureIds.contains( inputFeature.
id() ) )
183 testedFeatureIds.insert( inputFeature.
id() );
192 newGeometry = combinedClipGeom.
intersection( currentGeometry );
203 newGeometry = inputFeature.
geometry();
206 if ( !QgsOverlayUtils::sanitizeIntersectionResult( newGeometry, sinkType ) )
215 if ( singleClipFeature )
219 if ( !singleClipFeature )
222 feedback->
setProgress( 100.0 * static_cast< double >( i ) / clipGeoms.length() );
Wrapper for iterator of features from vector data provider or vector layer.
bool isCanceled() const
Tells whether the operation has been canceled already.
Use faster inserts, at the cost of updating the passed features to reflect changes made at the provid...
Base class for all map layer types.
QSet< QgsFeatureId > QgsFeatureIds
static Type multiType(Type type)
Returns the multi type for a WKB type.
Base class for providing feedback from a processing algorithm.
QList< QgsFeature > QgsFeatureList
void setProgress(double progress)
Sets the current progress for the feedback object.
QgsRectangle boundingBox() const
Returns the bounding box of the geometry.
QgsGeometry intersection(const QgsGeometry &geometry) const
Returns a geometry representing the points shared by this geometry and other.
A geometry is the spatial representation of a feature.
void setAttributes(const QgsAttributes &attrs)
Sets the feature's attributes.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
bool isSpatial() const FINAL
Returns true if this is a geometry layer and false in case of NoGeometry (table only) or UnknownGeome...
A feature sink output for processing algorithms.
const QgsAbstractGeometry * constGet() const
Returns a non-modifiable (const) reference to the underlying abstract geometry primitive.
QString lastError() const
Returns an error string referring to the last error encountered either when this geometry was created...
static GeometryType geometryType(Type type)
Returns the geometry type for a WKB type, e.g., both MultiPolygon and CurvePolygon would have a Polyg...
This class wraps a request for features to a vector layer (or directly its vector data provider)...
Custom exception class for processing related exceptions.
QgsGeometry difference(const QgsGeometry &geometry) const
Returns a geometry representing the points making up this geometry that do not make up other...
Algorithm supports in-place editing.
static QgsGeometryEngine * createGeometryEngine(const QgsAbstractGeometry *geometry)
Creates and returns a new geometry engine.
virtual Flags flags() const
Returns the flags indicating how and when the algorithm operates and should be exposed to users...
GeometryType
The geometry types are used to group QgsWkbTypes::Type in a coarse way.
An input feature source (such as vector layers) parameter for processing algorithms.
QgsCoordinateTransformContext transformContext() const
Returns the coordinate transform context.
void setGeometry(const QgsGeometry &geometry)
Set the feature's geometry.
bool hasGeometry() const
Returns true if the feature has an associated geometry.
QgsGeometry symDifference(const QgsGeometry &geometry) const
Returns a geometry representing the points making up this geometry that do not make up other...
QgsGeometry combine(const QgsGeometry &geometry) const
Returns a geometry representing all the points in this geometry and other (a union geometry operation...
bool isEmpty() const
Returns true if the geometry is empty (eg a linestring with no vertices, or a collection with no geom...
bool nextFeature(QgsFeature &f)
Represents a vector layer which manages a vector based data sets.
static Type flatType(Type type)
Returns the flat type for a WKB type.
Contains information about the context in which a processing algorithm is executed.
static QgsGeometry unaryUnion(const QVector< QgsGeometry > &geometries)
Compute the unary union on a list of geometries.
QgsWkbTypes::Type wkbType() const
Returns type of the geometry as a WKB type (point / linestring / polygon etc.)