27QString QgsExplodeAlgorithm::name()
const
29 return QStringLiteral(
"explodelines" );
32QString QgsExplodeAlgorithm::displayName()
const
34 return QObject::tr(
"Explode lines" );
37QStringList QgsExplodeAlgorithm::tags()
const
39 return QObject::tr(
"segments,parts" ).split(
',' );
42QString QgsExplodeAlgorithm::group()
const
44 return QObject::tr(
"Vector geometry" );
47QString QgsExplodeAlgorithm::groupId()
const
49 return QStringLiteral(
"vectorgeometry" );
52QString 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." );
61QString QgsExplodeAlgorithm::shortDescription()
const
63 return QObject::tr(
"Creates a line layer in which each feature represents a segment from an input line layer." );
71QList<int> QgsExplodeAlgorithm::inputLayerTypes()
const
81QgsExplodeAlgorithm *QgsExplodeAlgorithm::createInstance()
const
83 return new QgsExplodeAlgorithm();
86QString QgsExplodeAlgorithm::outputName()
const
88 return QObject::tr(
"Exploded" );
104 const std::vector<QgsGeometry> parts = extractAsParts( f.
geometry() );
107 features.reserve( parts.size() );
112 features << outputFeature;
128std::vector<QgsGeometry> QgsExplodeAlgorithm::extractAsParts(
const QgsGeometry &geometry )
const
132 std::vector<QgsGeometry> parts;
134 for (
int part = 0; part < collection->
numGeometries(); ++part )
136 std::vector<QgsGeometry> segments = curveAsSingleSegments( qgsgeometry_cast<const QgsCurve *>( collection->
geometryN( part ) ) );
137 parts.reserve( parts.size() + segments.size() );
138 std::move( std::begin( segments ), std::end( segments ), std::back_inserter( parts ) );
144 return curveAsSingleSegments( qgsgeometry_cast<const QgsCurve *>( geometry.
constGet() ) );
148std::vector<QgsGeometry> QgsExplodeAlgorithm::curveAsSingleSegments(
const QgsCurve *curve,
bool useCompoundCurves )
const
150 std::vector<QgsGeometry> parts;
157 const QgsLineString *line = qgsgeometry_cast<const QgsLineString *>( curve );
158 for (
int i = 0; i < line->
numPoints() - 1; ++i )
162 auto ls = std::make_unique<QgsLineString>( QVector<QgsPoint>() << ptA << ptB );
163 if ( !useCompoundCurves )
165 parts.emplace_back(
QgsGeometry( std::move( ls ) ) );
169 auto cc = std::make_unique<QgsCompoundCurve>();
170 cc->addCurve( ls.release() );
171 parts.emplace_back(
QgsGeometry( std::move( cc ) ) );
179 const QgsCircularString *
string = qgsgeometry_cast<const QgsCircularString *>( curve );
180 for (
int i = 0; i <
string->numPoints() - 2; i += 2 )
182 const QgsPoint ptA =
string->pointN( i );
183 const QgsPoint ptB =
string->pointN( i + 1 );
184 const QgsPoint ptC =
string->pointN( i + 2 );
185 auto cs = std::make_unique<QgsCircularString>();
187 if ( !useCompoundCurves )
189 parts.emplace_back(
QgsGeometry( std::move( cs ) ) );
193 auto cc = std::make_unique<QgsCompoundCurve>();
194 cc->addCurve( cs.release() );
195 parts.emplace_back(
QgsGeometry( std::move( cc ) ) );
203 const QgsCompoundCurve *compoundCurve = qgsgeometry_cast<const QgsCompoundCurve *>( curve );
204 for (
int i = 0; i < compoundCurve->
nCurves(); ++i )
206 std::vector<QgsGeometry> segments = curveAsSingleSegments( compoundCurve->
curveAt( i ),
true );
207 parts.reserve( parts.size() + segments.size() );
208 std::move( std::begin( segments ), std::end( segments ), std::back_inserter( parts ) );
ProcessingSourceType
Processing data source types.
@ VectorLine
Vector line layers.
@ RegeneratesPrimaryKey
Algorithm always drops any existing primary keys or FID values and regenerates them in outputs.
QFlags< ProcessingAlgorithmDocumentationFlag > ProcessingAlgorithmDocumentationFlags
Flags describing algorithm behavior for documentation purposes.
@ SkipGeometryValidityChecks
Invalid geometry checks should always be skipped. This flag can be useful for algorithms which always...
WkbType
The WKB type describes the number of dimensions a geometry has.
@ CompoundCurve
CompoundCurve.
@ CircularString
CircularString.
QFlags< ProcessingFeatureSourceFlag > ProcessingFeatureSourceFlags
Flags which control how QgsProcessingFeatureSource fetches features.
Qgis::WkbType wkbType() const
Returns the WKB type of the geometry.
Circular string geometry type.
Compound curve geometry type.
int nCurves() const
Returns the number of curves in the geometry.
const QgsCurve * curveAt(int i) const
Returns the curve at the specified index.
Abstract base class for curved geometry type.
QFlags< SinkFlag > SinkFlags
@ 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.
int numGeometries() const
Returns the number of geometries within the collection.
const QgsAbstractGeometry * geometryN(int n) const
Returns a const reference to a geometry from within the collection.
A geometry is the spatial representation of a feature.
const QgsAbstractGeometry * constGet() const
Returns a non-modifiable (const) reference to the underlying abstract geometry primitive.
bool isMultipart() const
Returns true if WKB of the geometry is of WKBMulti* type.
Line string geometry type, with support for z-dimension and m-values.
int numPoints() const override
Returns the number of points in the curve.
QgsPoint pointN(int i) const
Returns the specified point from inside the line string.
Point geometry type, with support for z-dimension and m-values.
Contains information about the context in which a processing algorithm is executed.
Base class for providing feedback from a processing algorithm.
static Qgis::WkbType singleType(Qgis::WkbType type)
Returns the single type for a WKB type.
static Qgis::WkbType flatType(Qgis::WkbType type)
Returns the flat type for a WKB type.
QVector< QgsPoint > QgsPointSequence
QList< QgsFeature > QgsFeatureList