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() );
101 outputFeature.setGeometry( part );
102 features << outputFeature;
108 std::vector<QgsGeometry> QgsExplodeAlgorithm::extractAsParts(
const QgsGeometry &geometry )
const 112 std::vector<QgsGeometry> parts;
114 for (
int part = 0; part < collection->
numGeometries(); ++part )
116 std::vector<QgsGeometry> segments = curveAsSingleSegments( qgsgeometry_cast< const QgsCurve * >( collection->
geometryN( part ) ) );
117 parts.reserve( parts.size() + segments.size() );
118 std::move( std::begin( segments ), std::end( segments ), std::back_inserter( parts ) );
124 return curveAsSingleSegments( qgsgeometry_cast< const QgsCurve * >( geometry.
constGet() ) );
128 std::vector<QgsGeometry> QgsExplodeAlgorithm::curveAsSingleSegments(
const QgsCurve *curve,
bool useCompoundCurves )
const 130 std::vector<QgsGeometry> parts;
138 for (
int i = 0; i < line->
numPoints() - 1; ++i )
142 std::unique_ptr< QgsLineString > ls = qgis::make_unique< QgsLineString >( QVector< QgsPoint >() << ptA << ptB );
143 if ( !useCompoundCurves )
145 parts.emplace_back(
QgsGeometry( std::move( ls ) ) );
149 std::unique_ptr< QgsCompoundCurve > cc = qgis::make_unique< QgsCompoundCurve >();
150 cc->addCurve( ls.release() );
151 parts.emplace_back(
QgsGeometry( std::move( cc ) ) );
160 for (
int i = 0; i <
string->numPoints() - 2; i += 2 )
163 QgsPoint ptB =
string->pointN( i + 1 );
164 QgsPoint ptC =
string->pointN( i + 2 );
165 std::unique_ptr< QgsCircularString > cs = qgis::make_unique< QgsCircularString >();
167 if ( !useCompoundCurves )
169 parts.emplace_back(
QgsGeometry( std::move( cs ) ) );
173 std::unique_ptr< QgsCompoundCurve > cc = qgis::make_unique< QgsCompoundCurve >();
174 cc->addCurve( cs.release() );
175 parts.emplace_back(
QgsGeometry( std::move( cc ) ) );
184 for (
int i = 0; i < compoundCurve->
nCurves(); ++i )
186 std::vector<QgsGeometry> segments = curveAsSingleSegments( compoundCurve->
curveAt( i ), true );
187 parts.reserve( parts.size() + segments.size() );
188 std::move( std::begin( segments ), std::end( segments ), std::back_inserter( parts ) );
static Type singleType(Type type)
Returns the single type for a WKB type.
Base class for providing feedback from a processing algorithm.
bool isMultipart() const
Returns true if WKB of the geometry is of WKBMulti* type.
QList< QgsFeature > QgsFeatureList
A geometry is the spatial representation of a feature.
void setAttributes(const QgsAttributes &attrs)
Sets the feature's attributes.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
bool hasGeometry() const
Returns true if the feature has an associated geometry.
int numPoints() const override
Returns the number of points in the curve.
Type
The WKB type describes the number of dimensions a geometry has.
T qgsgeometry_cast(const QgsAbstractGeometry *geom)
Abstract base class for curved geometry type.
QgsWkbTypes::Type wkbType() const
Returns the WKB type of the geometry.
Point geometry type, with support for z-dimension and m-values.
int numGeometries() const
Returns the number of geometries within the collection.
const QgsAbstractGeometry * constGet() const
Returns a non-modifiable (const) reference to the underlying abstract geometry primitive.
int nCurves() const
Returns the number of curves in the geometry.
QVector< QgsPoint > QgsPointSequence
Line string geometry type, with support for z-dimension and m-values.
const QgsAbstractGeometry * geometryN(int n) const
Returns a const reference to a geometry from within the collection.
const QgsCurve * curveAt(int i) const
Returns the curve at the specified index.
QgsPoint pointN(int i) const
Returns the specified point from inside the line string.
SourceType
Data source types enum.
Compound curve geometry type.
Circular string geometry type.
static Type flatType(Type type)
Returns the flat type for a WKB type.
Contains information about the context in which a processing algorithm is executed.