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 = std::make_unique< QgsLineString >( QVector< QgsPoint >() << ptA << ptB );
148 if ( !useCompoundCurves )
150 parts.emplace_back(
QgsGeometry( std::move( ls ) ) );
154 std::unique_ptr< QgsCompoundCurve > cc = std::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 = std::make_unique< QgsCircularString >();
172 if ( !useCompoundCurves )
174 parts.emplace_back(
QgsGeometry( std::move( cs ) ) );
178 std::unique_ptr< QgsCompoundCurve > cc = std::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 ) );
QgsWkbTypes::Type wkbType() const SIP_HOLDGIL
Returns the WKB type of the geometry.
Circular string geometry type.
Compound curve geometry type.
const QgsCurve * curveAt(int i) const SIP_HOLDGIL
Returns the curve at the specified index.
int nCurves() const SIP_HOLDGIL
Returns the number of curves in the geometry.
Abstract base class for curved geometry type.
@ 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 SIP_HOLDGIL
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 SIP_HOLDGIL
Returns a non-modifiable (const) reference to the underlying abstract geometry primitive.
bool isMultipart() const SIP_HOLDGIL
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 SIP_HOLDGIL
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.
SourceType
Data source types enum.
@ TypeVectorLine
Vector line layers.
Type
The WKB type describes the number of dimensions a geometry has.
static Type singleType(Type type) SIP_HOLDGIL
Returns the single type for a WKB type.
static Type flatType(Type type) SIP_HOLDGIL
Returns the flat type for a WKB type.
QVector< QgsPoint > QgsPointSequence
QList< QgsFeature > QgsFeatureList