27 QString QgsExplodeAlgorithm::name()
const
29 return QStringLiteral(
"explodelines" );
32 QString QgsExplodeAlgorithm::displayName()
const
34 return QObject::tr(
"Explode lines" );
37 QStringList QgsExplodeAlgorithm::tags()
const
39 return QObject::tr(
"segments,parts" ).split(
',' );
42 QString QgsExplodeAlgorithm::group()
const
44 return QObject::tr(
"Vector geometry" );
47 QString QgsExplodeAlgorithm::groupId()
const
49 return QStringLiteral(
"vectorgeometry" );
52 QString QgsExplodeAlgorithm::shortHelpString()
const
54 return QObject::tr(
"This algorithm takes a lines layer and creates a new one in which each line is replaced by a set of "
55 "lines representing the segments in the original line. Each line in the resulting layer contains only a "
56 "start and an end point, with no intermediate nodes between them.\n\n"
57 "If the input layer consists of CircularStrings or CompoundCurves, the output layer will be of the "
58 "same type and contain only single curve segments." );
61 QList<int> QgsExplodeAlgorithm::inputLayerTypes()
const
71 QgsExplodeAlgorithm *QgsExplodeAlgorithm::createInstance()
const
73 return new QgsExplodeAlgorithm();
76 QString QgsExplodeAlgorithm::outputName()
const
78 return QObject::tr(
"Exploded" );
94 const std::vector<QgsGeometry> parts = extractAsParts( f.
geometry() );
97 features.reserve( parts.size() );
102 features << outputFeature;
108 QgsFeatureSink::SinkFlags QgsExplodeAlgorithm::sinkFlags()
const
113 std::vector<QgsGeometry> QgsExplodeAlgorithm::extractAsParts(
const QgsGeometry &geometry )
const
117 std::vector<QgsGeometry> parts;
119 for (
int part = 0; part < collection->
numGeometries(); ++part )
121 std::vector<QgsGeometry> segments = curveAsSingleSegments( qgsgeometry_cast< const QgsCurve * >( collection->
geometryN( part ) ) );
122 parts.reserve( parts.size() + segments.size() );
123 std::move( std::begin( segments ), std::end( segments ), std::back_inserter( parts ) );
129 return curveAsSingleSegments( qgsgeometry_cast< const QgsCurve * >( geometry.
constGet() ) );
133 std::vector<QgsGeometry> QgsExplodeAlgorithm::curveAsSingleSegments(
const QgsCurve *curve,
bool useCompoundCurves )
const
135 std::vector<QgsGeometry> parts;
142 const QgsLineString *line = qgsgeometry_cast< const QgsLineString * >( curve );
143 for (
int i = 0; i < line->
numPoints() - 1; ++i )
147 std::unique_ptr< QgsLineString > ls = qgis::make_unique< QgsLineString >( QVector< QgsPoint >() << ptA << ptB );
148 if ( !useCompoundCurves )
150 parts.emplace_back(
QgsGeometry( std::move( ls ) ) );
154 std::unique_ptr< QgsCompoundCurve > cc = qgis::make_unique< QgsCompoundCurve >();
155 cc->addCurve( ls.release() );
156 parts.emplace_back(
QgsGeometry( std::move( cc ) ) );
164 const QgsCircularString *
string = qgsgeometry_cast< const QgsCircularString * >( curve );
165 for (
int i = 0; i <
string->numPoints() - 2; i += 2 )
168 QgsPoint ptB =
string->pointN( i + 1 );
169 QgsPoint ptC =
string->pointN( i + 2 );
170 std::unique_ptr< QgsCircularString > cs = qgis::make_unique< QgsCircularString >();
172 if ( !useCompoundCurves )
174 parts.emplace_back(
QgsGeometry( std::move( cs ) ) );
178 std::unique_ptr< QgsCompoundCurve > cc = qgis::make_unique< QgsCompoundCurve >();
179 cc->addCurve( cs.release() );
180 parts.emplace_back(
QgsGeometry( std::move( cc ) ) );
188 const QgsCompoundCurve *compoundCurve = qgsgeometry_cast< QgsCompoundCurve * >( curve );
189 for (
int i = 0; i < compoundCurve->
nCurves(); ++i )
191 std::vector<QgsGeometry> segments = curveAsSingleSegments( compoundCurve->
curveAt( i ),
true );
192 parts.reserve( parts.size() + segments.size() );
193 std::move( std::begin( segments ), std::end( segments ), std::back_inserter( parts ) );