23 QString QgsClipAlgorithm::name()
const 25 return QStringLiteral(
"clip" );
28 QString QgsClipAlgorithm::displayName()
const 30 return QObject::tr(
"Clip" );
33 QStringList QgsClipAlgorithm::tags()
const 35 return QObject::tr(
"clip,intersect,intersection,mask" ).split(
',' );
38 QString QgsClipAlgorithm::group()
const 40 return QObject::tr(
"Vector overlay" );
43 QString QgsClipAlgorithm::groupId()
const 45 return QStringLiteral(
"vectoroverlay" );
48 void QgsClipAlgorithm::initAlgorithm(
const QVariantMap & )
56 QString QgsClipAlgorithm::shortHelpString()
const 58 return QObject::tr(
"This algorithm clips a vector layer using the polygons of an additional polygons layer. Only the parts of the features " 59 "in the input layer that falls within the polygons of the clipping layer will be added to the resulting layer.\n\n" 60 "The attributes of the features are not modified, although properties such as area or length of the features will " 61 "be modified by the clipping operation. If such properties are stored as attributes, those attributes will have to " 62 "be manually updated." );
65 QgsClipAlgorithm *QgsClipAlgorithm::createInstance()
const 67 return new QgsClipAlgorithm();
72 std::unique_ptr< QgsFeatureSource > featureSource( parameterAsSource( parameters, QStringLiteral(
"INPUT" ), context ) );
76 std::unique_ptr< QgsFeatureSource > maskSource( parameterAsSource( parameters, QStringLiteral(
"OVERLAY" ), context ) );
81 std::unique_ptr< QgsFeatureSink > sink( parameterAsSink( parameters, QStringLiteral(
"OUTPUT" ), context, dest, featureSource->fields(),
QgsWkbTypes::multiType( featureSource->wkbType() ), featureSource->sourceCrs() ) );
87 QVector< QgsGeometry > clipGeoms;
97 outputs.insert( QStringLiteral(
"OUTPUT" ), dest );
99 if ( clipGeoms.isEmpty() )
103 bool singleClipFeature =
false;
105 if ( clipGeoms.length() > 1 )
108 if ( combinedClipGeom.
isEmpty() )
112 singleClipFeature =
false;
116 combinedClipGeom = clipGeoms.at( 0 );
117 singleClipFeature =
true;
122 engine->prepareGeometry();
127 Q_FOREACH (
const QgsGeometry &clipGeom, clipGeoms )
141 if ( inputFeatures.isEmpty() )
145 if ( singleClipFeature )
146 step = 100.0 / inputFeatures.length();
149 Q_FOREACH (
const QgsFeature &inputFeature, inputFeatures )
159 if ( testedFeatureIds.contains( inputFeature.
id() ) )
164 testedFeatureIds.insert( inputFeature.
id() );
173 newGeometry = combinedClipGeom.
intersection( currentGeometry );
184 newGeometry = inputFeature.
geometry();
193 if ( singleClipFeature )
197 if ( !singleClipFeature )
200 feedback->
setProgress( 100.0 * static_cast< double >( i ) / clipGeoms.length() );
Wrapper for iterator of features from vector data provider or vector layer.
Use faster inserts, at the cost of updating the passed features to reflect changes made at the provid...
QgsGeometry combine(const QgsGeometry &geometry) const
Returns a geometry representing all the points in this geometry and other (a union geometry operation...
static Type multiType(Type type)
Returns the multi type for a WKB type.
Base class for providing feedback from a processing algorithm.
QSet< QgsFeatureId > QgsFeatureIds
QList< QgsFeature > QgsFeatureList
QgsWkbTypes::Type wkbType() const
Returns type of the geometry as a WKB type (point / linestring / polygon etc.)
void setProgress(double progress)
Sets the current progress for the feedback object.
A geometry is the spatial representation of a feature.
void setAttributes(const QgsAttributes &attrs)
Sets the feature's attributes.
QgsGeometry intersection(const QgsGeometry &geometry) const
Returns a geometry representing the points shared by this geometry and other.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
bool hasGeometry() const
Returns true if the feature has an associated geometry.
A feature sink output for processing algorithms.
This class wraps a request for features to a vector layer (or directly its vector data provider)...
Custom exception class for processing related exceptions.
QgsCoordinateTransformContext transformContext() const
Returns the coordinate transform context.
bool isEmpty() const
Returns true if the geometry is empty (eg a linestring with no vertices, or a collection with no geom...
QgsGeometry geometry() const
Returns the geometry associated with this feature.
static QgsGeometryEngine * createGeometryEngine(const QgsAbstractGeometry *geometry)
Creates and returns a new geometry engine.
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...
bool isCanceled() const
Tells whether the operation has been canceled already.
An input feature source (such as vector layers) parameter for processing algorithms.
QgsRectangle boundingBox() const
Returns the bounding box of the geometry.
void setGeometry(const QgsGeometry &geometry)
Set the feature's geometry.
bool nextFeature(QgsFeature &f)
QgsGeometry symDifference(const QgsGeometry &geometry) const
Returns a geometry representing the points making up this geometry that do not make up other...
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.
QgsGeometry difference(const QgsGeometry &geometry) const
Returns a geometry representing the points making up this geometry that do not make up other...