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;
140 const QgsFeatureIds splitLineCandidates = qgis::listToSet( splitLinesIndex.intersects( originalGeometry.
boundingBox() ) );
141 if ( !splitLineCandidates.empty() )
143 QVector< QgsGeometry > splittingLines;
146 std::unique_ptr< QgsGeometryEngine > originalGeometryEngine;
148 for (
QgsFeatureId splitLineCandidateId : splitLineCandidates )
151 if ( sameLayer && inFeatureA.
id() == splitLineCandidateId )
154 const QgsGeometry splitLineCandidate = splitLinesIndex.geometry( splitLineCandidateId );
155 if ( !originalGeometryEngine )
158 originalGeometryEngine->prepareGeometry();
161 if ( originalGeometryEngine->intersects( splitLineCandidate.
constGet() ) )
164 splittingLines.append( splitGeomParts );
168 if ( !splittingLines.empty() )
170 for (
const QgsGeometry &splitGeom : std::as_const( splittingLines ) )
173 QVector< QgsGeometry > outGeoms;
177 splitGeomEngine->prepareGeometry();
178 while ( !inGeoms.empty() )
189 if ( splitGeomEngine->intersects( inGeom.
constGet() ) )
192 if ( splitterPList.empty() )
207 QVector< QgsGeometry > newGeometries;
221 outGeoms.append( inGeom );
225 inGeoms.append( inGeom );
226 inGeoms.append( newGeometries );
231 outGeoms.append( inGeom );
236 outGeoms.append( inGeom );
245 QVector< QgsGeometry > parts;
246 for (
const QgsGeometry &aGeom : std::as_const( inGeoms ) )
256 int numPoints = aGeom.constGet()->nCoordinates();
258 if ( numPoints <= 2 )
260 if ( numPoints == 2 )
261 passed = !
static_cast< const QgsCurve *
>( aGeom.constGet() )->isClosed();
268 parts.append( aGeom );
282 outputs.insert( QStringLiteral(
"OUTPUT" ), dest );