23 QString QgsSplitWithLinesAlgorithm::name()
const 25 return QStringLiteral(
"splitwithlines" );
28 QString QgsSplitWithLinesAlgorithm::displayName()
const 30 return QObject::tr(
"Split with lines" );
33 QStringList QgsSplitWithLinesAlgorithm::tags()
const 35 return QObject::tr(
"split,cut,lines" ).split(
',' );
38 QString QgsSplitWithLinesAlgorithm::group()
const 40 return QObject::tr(
"Vector overlay" );
43 QString QgsSplitWithLinesAlgorithm::groupId()
const 45 return QStringLiteral(
"vectoroverlay" );
48 void QgsSplitWithLinesAlgorithm::initAlgorithm(
const QVariantMap & )
57 QString QgsSplitWithLinesAlgorithm::shortHelpString()
const 59 return QObject::tr(
"This algorithm splits the lines or polygons in one layer using the lines in another layer to define the breaking points. " 60 "Intersection between geometries in both layers are considered as split points." );
63 QgsSplitWithLinesAlgorithm *QgsSplitWithLinesAlgorithm::createInstance()
const 65 return new QgsSplitWithLinesAlgorithm();
70 std::unique_ptr< QgsFeatureSource > source( parameterAsSource( parameters, QStringLiteral(
"INPUT" ), context ) );
74 std::unique_ptr< QgsFeatureSource > linesSource( parameterAsSource( parameters, QStringLiteral(
"LINES" ), context ) );
78 bool sameLayer = parameters.value( QStringLiteral(
"INPUT" ) ) == parameters.value( QStringLiteral(
"LINES" ) );
81 std::unique_ptr< QgsFeatureSink > sink( parameterAsSink( parameters, QStringLiteral(
"OUTPUT" ), context, dest, source->fields(),
87 QMap< QgsFeatureId, QgsGeometry > splitGeoms;
101 splitGeoms.insert( aSplitFeature.
id(), aSplitFeature.
geometry() );
108 double step = source->featureCount() > 0 ? 100.0 / source->featureCount() : 1;
131 if ( !lines.empty() )
133 QVector< QgsGeometry > splittingLines;
136 std::unique_ptr< QgsGeometryEngine > engine;
141 if ( sameLayer && inFeatureA.
id() == line )
148 engine->prepareGeometry();
151 if ( engine->intersects( splitGeom.
constGet() ) )
154 splittingLines.append( splitGeomParts );
158 if ( !splittingLines.empty() )
160 for (
const QgsGeometry &splitGeom : qgis::as_const( splittingLines ) )
162 QVector<QgsPointXY> splitterPList;
163 QVector< QgsGeometry > outGeoms;
167 splitGeomEngine->prepareGeometry();
168 while ( !inGeoms.empty() )
179 if ( splitGeomEngine->intersects( inGeom.
constGet() ) )
182 if ( splitterPList.empty() )
197 QVector< QgsGeometry > newGeometries;
198 QVector<QgsPointXY> topologyTestPoints;
209 outGeoms.append( inGeom );
213 inGeoms.append( inGeom );
214 inGeoms.append( newGeometries );
219 outGeoms.append( inGeom );
224 outGeoms.append( inGeom );
233 QVector< QgsGeometry > parts;
234 for (
const QgsGeometry &aGeom : qgis::as_const( inGeoms ) )
244 int numPoints = aGeom.constGet()->nCoordinates();
246 if ( numPoints <= 2 )
248 if ( numPoints == 2 )
249 passed = !
static_cast< const QgsCurve *
>( aGeom.constGet() )->isClosed();
256 parts.append( aGeom );
269 outputs.insert( QStringLiteral(
"OUTPUT" ), dest );
QgsFeatureRequest & setDestinationCrs(const QgsCoordinateReferenceSystem &crs, const QgsCoordinateTransformContext &context)
Sets the destination crs for feature's geometries.
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...
static Type multiType(Type type)
Returns the multi type for a WKB type.
Base class for providing feedback from a processing algorithm.
QVector< QgsRingSequence > QgsCoordinateSequence
QSet< QgsFeatureId > QgsFeatureIds
A class to represent a 2D point.
void setProgress(double progress)
Sets the current progress for the feedback object.
QgsFeatureRequest & setSubsetOfAttributes(const QgsAttributeList &attrs)
Set a subset of attributes that will be fetched.
A geometry is the spatial representation of a feature.
void setAttributes(const QgsAttributes &attrs)
Sets the feature's attributes.
bool insertFeature(const QgsFeature &feature)
Adds a feature to the index.
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.
OperationResult
Success or failure of a geometry operation.
A feature sink output for processing algorithms.
bool isGeosEqual(const QgsGeometry &) const
Compares the geometry with another geometry using GEOS.
QVector< QgsGeometry > asGeometryCollection() const
Returns contents of the geometry as a list of geometries.
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.
QgsCoordinateTransformContext transformContext() const
Returns the coordinate transform context.
Abstract base class for curved geometry type.
QgsGeometry geometry() const
Returns the geometry associated with this feature.
Point geometry type, with support for z-dimension and m-values.
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.
QVector< QgsPoint > QgsPointSequence
virtual QgsCoordinateSequence coordinateSequence() const =0
Retrieves the sequence of geometries, rings and nodes.
QVector< QgsPointSequence > QgsRingSequence
A spatial index for QgsFeature objects.
bool isCanceled() const
Tells whether the operation has been canceled already.
OperationResult splitGeometry(const QVector< QgsPointXY > &splitLine, QVector< QgsGeometry > &newGeometries, bool topological, QVector< QgsPointXY > &topologyTestPoints)
Splits this geometry according to a given line.
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.
QList< int > QgsAttributeList
bool nextFeature(QgsFeature &f)
Contains information about the context in which a processing algorithm is executed.
QList< QgsFeatureId > intersects(const QgsRectangle &rectangle) const
Returns a list of features with a bounding box which intersects the specified rectangle.