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();
68 QgsProcessingAlgorithm::Flags QgsSplitWithLinesAlgorithm::flags()
const 75 bool QgsSplitWithLinesAlgorithm::supportInPlaceEdit(
const QgsMapLayer *l )
const 89 std::unique_ptr< QgsFeatureSource > source( parameterAsSource( parameters, QStringLiteral(
"INPUT" ), context ) );
93 std::unique_ptr< QgsFeatureSource > linesSource( parameterAsSource( parameters, QStringLiteral(
"LINES" ), context ) );
97 bool sameLayer = parameters.value( QStringLiteral(
"INPUT" ) ) == parameters.value( QStringLiteral(
"LINES" ) );
100 std::unique_ptr< QgsFeatureSink > sink( parameterAsSink( parameters, QStringLiteral(
"OUTPUT" ), context, dest, source->fields(),
106 QMap< QgsFeatureId, QgsGeometry > splitGeoms;
120 splitGeoms.insert( aSplitFeature.
id(), aSplitFeature.
geometry() );
127 double step = source->featureCount() > 0 ? 100.0 / source->featureCount() : 1;
150 if ( !lines.empty() )
152 QVector< QgsGeometry > splittingLines;
155 std::unique_ptr< QgsGeometryEngine > engine;
160 if ( sameLayer && inFeatureA.
id() == line )
167 engine->prepareGeometry();
170 if ( engine->intersects( splitGeom.
constGet() ) )
173 splittingLines.append( splitGeomParts );
177 if ( !splittingLines.empty() )
179 for (
const QgsGeometry &splitGeom : qgis::as_const( splittingLines ) )
182 QVector< QgsGeometry > outGeoms;
186 splitGeomEngine->prepareGeometry();
187 while ( !inGeoms.empty() )
198 if ( splitGeomEngine->intersects( inGeom.
constGet() ) )
201 if ( splitterPList.empty() )
216 QVector< QgsGeometry > newGeometries;
228 outGeoms.append( inGeom );
232 inGeoms.append( inGeom );
233 inGeoms.append( newGeometries );
238 outGeoms.append( inGeom );
243 outGeoms.append( inGeom );
252 QVector< QgsGeometry > parts;
253 for (
const QgsGeometry &aGeom : qgis::as_const( inGeoms ) )
263 int numPoints = aGeom.constGet()->nCoordinates();
265 if ( numPoints <= 2 )
267 if ( numPoints == 2 )
268 passed = !
static_cast< const QgsCurve *
>( aGeom.constGet() )->isClosed();
275 parts.append( aGeom );
288 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...
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.
QVector< QgsRingSequence > QgsCoordinateSequence
void setProgress(double progress)
Sets the current progress for the feedback object.
virtual Flags flags() const
Returns the flags indicating how and when the algorithm operates and should be exposed to users...
QgsWkbTypes::GeometryType geometryType() const
Returns point, line or polygon.
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 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.
This flag indicates, that a primary key field cannot be guaranteed to be unique and the sink should i...
QVector< QgsGeometry > asGeometryCollection() const
Returns contents of the geometry as a list of geometries.
QgsFeatureRequest & setNoAttributes()
Set that no attributes will be fetched.
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.
Point geometry type, with support for z-dimension and m-values.
Algorithm supports in-place editing.
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.
Q_DECL_DEPRECATED 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.
bool addFeature(QgsFeature &feature, QgsFeatureSink::Flags flags=nullptr) override
Adds a feature to the index.
bool nextFeature(QgsFeature &f)
Represents a vector layer which manages a vector based data sets.
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.