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
77 const QgsVectorLayer *layer = qobject_cast< const QgsVectorLayer * >( l );
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(),
117 double step = source->featureCount() > 0 ? 100.0 / source->featureCount() : 1;
139 const QgsFeatureIds splitLineCandidates = qgis::listToSet( splitLinesIndex.intersects( originalGeometry.
boundingBox() ) );
140 if ( !splitLineCandidates.empty() )
142 QVector< QgsGeometry > splittingLines;
145 std::unique_ptr< QgsGeometryEngine > originalGeometryEngine;
147 for (
QgsFeatureId splitLineCandidateId : splitLineCandidates )
150 if ( sameLayer && inFeatureA.
id() == splitLineCandidateId )
153 const QgsGeometry splitLineCandidate = splitLinesIndex.geometry( splitLineCandidateId );
154 if ( !originalGeometryEngine )
157 originalGeometryEngine->prepareGeometry();
160 if ( originalGeometryEngine->intersects( splitLineCandidate.
constGet() ) )
163 splittingLines.append( splitGeomParts );
167 if ( !splittingLines.empty() )
169 for (
const QgsGeometry &splitGeom : std::as_const( splittingLines ) )
172 QVector< QgsGeometry > outGeoms;
176 splitGeomEngine->prepareGeometry();
177 while ( !inGeoms.empty() )
188 if ( splitGeomEngine->intersects( inGeom.
constGet() ) )
191 if ( splitterPList.empty() )
206 QVector< QgsGeometry > newGeometries;
220 outGeoms.append( inGeom );
224 inGeoms.append( inGeom );
225 inGeoms.append( newGeometries );
230 outGeoms.append( inGeom );
235 outGeoms.append( inGeom );
244 QVector< QgsGeometry > parts;
245 for (
const QgsGeometry &aGeom : std::as_const( inGeoms ) )
255 int numPoints = aGeom.constGet()->nCoordinates();
257 if ( numPoints <= 2 )
259 if ( numPoints == 2 )
260 passed = !
static_cast< const QgsCurve *
>( aGeom.constGet() )->isClosed();
267 parts.append( aGeom );
280 outputs.insert( QStringLiteral(
"OUTPUT" ), dest );
virtual QgsCoordinateSequence coordinateSequence() const =0
Retrieves the sequence of geometries, rings and nodes.
Abstract base class for curved geometry type.
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).
QgsFeatureRequest & setDestinationCrs(const QgsCoordinateReferenceSystem &crs, const QgsCoordinateTransformContext &context)
Sets the destination crs for feature's geometries.
QgsFeatureRequest & setNoAttributes()
Set that no attributes will be fetched.
@ FastInsert
Use faster inserts, at the cost of updating the passed features to reflect changes made at the provid...
@ RegeneratePrimaryKey
This flag indicates, that a primary key field cannot be guaranteed to be unique and the sink should i...
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.
QVector< QgsGeometry > asGeometryCollection() const
Returns contents of the geometry as a list of geometries.
Q_DECL_DEPRECATED OperationResult splitGeometry(const QVector< QgsPointXY > &splitLine, QVector< QgsGeometry > &newGeometries, bool topological, QVector< QgsPointXY > &topologyTestPoints, bool splitFeature=true)
Splits this geometry according to a given line.
OperationResult
Success or failure of a geometry operation.
@ Success
Operation succeeded.
static QgsGeometryEngine * createGeometryEngine(const QgsAbstractGeometry *geometry)
Creates and returns a new geometry engine representing the specified geometry.
double hausdorffDistance(const QgsGeometry &geom) const
Returns the Hausdorff distance between this geometry and geom.
QgsRectangle boundingBox() const
Returns the bounding box of the geometry.
Base class for all map layer types.
Point geometry type, with support for z-dimension and m-values.
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.
A feature sink output for processing algorithms.
An input feature source (such as vector layers) parameter for processing algorithms.
@ TypeVectorLine
Vector line layers.
@ TypeVectorPolygon
Vector polygon layers.
A spatial index for QgsFeature objects.
@ FlagStoreFeatureGeometries
Indicates that the spatial index should also store feature geometries. This requires more memory,...
Represents a vector layer which manages a vector based data sets.
Q_INVOKABLE QgsWkbTypes::GeometryType geometryType() const
Returns point, line or polygon.
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 multiType(Type type) SIP_HOLDGIL
Returns the multi type for a WKB type.
QVector< QgsRingSequence > QgsCoordinateSequence
QVector< QgsPointSequence > QgsRingSequence
QVector< QgsPoint > QgsPointSequence
QSet< QgsFeatureId > QgsFeatureIds
qint64 QgsFeatureId
64 bit feature ids negative numbers are used for uncommitted/newly added features