25 QString QgsExtractVerticesAlgorithm::name()
const 27 return QStringLiteral(
"extractvertices" );
30 QString QgsExtractVerticesAlgorithm::displayName()
const 32 return QObject::tr(
"Extract vertices" );
35 QStringList QgsExtractVerticesAlgorithm::tags()
const 37 return QObject::tr(
"points,vertex,nodes" ).split(
',' );
40 QString QgsExtractVerticesAlgorithm::group()
const 42 return QObject::tr(
"Vector geometry" );
45 QString QgsExtractVerticesAlgorithm::groupId()
const 47 return QStringLiteral(
"vectorgeometry" );
50 QString QgsExtractVerticesAlgorithm::shortHelpString()
const 52 return QObject::tr(
"This algorithm takes a line or polygon layer and generates a point layer with points representing the vertices in the input lines or polygons. The attributes associated to each point are the same ones associated to the line or polygon that the point belongs to." ) +
53 QStringLiteral(
"\n\n" ) +
54 QObject::tr(
"Additional fields are added to the point indicating the vertex index (beginning at 0), the vertex’s part and its index within the part (as well as its ring for polygons), distance along original geometry and bisector angle of vertex for original geometry." );
57 QgsExtractVerticesAlgorithm *QgsExtractVerticesAlgorithm::createInstance()
const 59 return new QgsExtractVerticesAlgorithm();
62 void QgsExtractVerticesAlgorithm::initAlgorithm(
const QVariantMap & )
71 std::unique_ptr< QgsProcessingFeatureSource > featureSource( parameterAsSource( parameters, QStringLiteral(
"INPUT" ), context ) );
85 QgsFields outputFields = featureSource->fields();
86 outputFields.
append(
QgsField( QStringLiteral(
"vertex_index" ), QVariant::Int, QString(), 10, 0 ) );
87 outputFields.
append(
QgsField( QStringLiteral(
"vertex_part" ), QVariant::Int, QString(), 10, 0 ) );
90 outputFields.
append(
QgsField( QStringLiteral(
"vertex_part_ring" ), QVariant::Int, QString(), 10, 0 ) );
92 outputFields.
append(
QgsField( QStringLiteral(
"vertex_part_index" ), QVariant::Int, QString(), 10, 0 ) );
93 outputFields.
append(
QgsField( QStringLiteral(
"distance" ), QVariant::Double, QString(), 20, 14 ) );
94 outputFields.
append(
QgsField( QStringLiteral(
"angle" ), QVariant::Double, QString(), 20, 14 ) );
97 std::unique_ptr< QgsFeatureSink > sink( parameterAsSink( parameters, QStringLiteral(
"OUTPUT" ), context, dest, outputFields, outputWkbType, featureSource->sourceCrs() ) );
101 double step = featureSource->featureCount() > 0 ? 100.0 / featureSource->featureCount() : 1;
121 double cumulativeDistance = 0.0;
132 attrs << vertexId.
ring;
135 << cumulativeDistance
146 cumulativeDistance += distanceToNext;
153 outputs.insert( QStringLiteral(
"OUTPUT" ), dest );
Wrapper for iterator of features from vector data provider or vector layer.
Use faster inserts, at the cost of updating the passed features to reflect changes made at the provid...
Base class for providing feedback from a processing algorithm.
Invalid geometry checks should always be skipped. This flag can be useful for algorithms which always...
bool isNull() const
Returns true if the geometry is null (ie, contains no underlying geometry accessible via geometry() )...
QgsVertexId vertexId() const
Returns vertex ID of the current item.
void setProgress(double progress)
Sets the current progress for the feedback object.
virtual double vertexAngle(QgsVertexId vertex) const =0
Returns approximate angle at a vertex.
Container of fields for a vector layer.
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...
static bool hasZ(Type type)
Tests whether a WKB type contains the z-dimension.
double ANALYSIS_EXPORT angle(QgsPoint *p1, QgsPoint *p2, QgsPoint *p3, QgsPoint *p4)
Calculates the angle between two segments (in 2 dimension, z-values are ignored)
A feature sink output for processing algorithms.
Type
The WKB type describes the number of dimensions a geometry has.
virtual double segmentLength(QgsVertexId startVertex) const =0
Returns the length of the segment of the geometry which begins at startVertex.
static Type addM(Type type)
Adds the m dimension to a WKB type and returns the new type.
Utility class for identifying a unique vertex within a geometry.
vertex_iterator vertices_end() const
Returns STL-style iterator pointing to the imaginary vertex after the last vertex of the geometry...
static GeometryType geometryType(Type type)
Returns the geometry type for a WKB type, e.g., both MultiPolygon and CurvePolygon would have a Polyg...
static Type addZ(Type type)
Adds the z dimension to a WKB type and returns the new type.
This class wraps a request for features to a vector layer (or directly its vector data provider)...
Custom exception class for processing related exceptions.
bool append(const QgsField &field, FieldOrigin origin=OriginProvider, int originIndex=-1)
Append a field. The field must have unique name, otherwise it is rejected (returns false) ...
Encapsulate a field in an attribute table or data source.
QgsGeometry geometry() const
Returns the geometry associated with this feature.
The vertex_iterator class provides STL-style iterator for vertices.
const QgsAbstractGeometry * constGet() const
Returns a non-modifiable (const) reference to the underlying abstract geometry primitive.
bool isCanceled() const
Tells whether the operation has been canceled already.
An input feature source (such as vector layers) parameter for processing algorithms.
void setGeometry(const QgsGeometry &geometry)
Set the feature's geometry.
static bool hasM(Type type)
Tests whether a WKB type contains m values.
vertex_iterator vertices_begin() const
Returns STL-style iterator pointing to the first vertex of the geometry.
bool nextFeature(QgsFeature &f)
Contains information about the context in which a processing algorithm is executed.