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 : qgis::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 : qgis::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 );