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(),
105 QMap< QgsFeatureId, QgsGeometry > splitGeoms;
120 splitGeoms.insert( aSplitFeature.
id(), aSplitFeature.
geometry() );
127 double step = source->featureCount() > 0 ? 100.0 / source->featureCount() : 1;
145 outFeat.setAttributes( inFeatureA.
attributes() );
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 );
280 outFeat.setGeometry( g );
288 outputs.insert( QStringLiteral(
"OUTPUT" ), dest );