25QString QgsExtractSpecificVerticesAlgorithm::name()
const
27 return QStringLiteral(
"extractspecificvertices" );
30QString QgsExtractSpecificVerticesAlgorithm::displayName()
const
32 return QObject::tr(
"Extract specific vertices" );
35QStringList QgsExtractSpecificVerticesAlgorithm::tags()
const
37 return QObject::tr(
"points,vertex,nodes" ).split(
',' );
40QString QgsExtractSpecificVerticesAlgorithm::group()
const
42 return QObject::tr(
"Vector geometry" );
45QString QgsExtractSpecificVerticesAlgorithm::groupId()
const
47 return QStringLiteral(
"vectorgeometry" );
50QString QgsExtractSpecificVerticesAlgorithm::shortHelpString()
const
52 return QObject::tr(
"This algorithm takes a vector layer and generates a point layer with points "
53 "representing specific vertices in the input geometries. For instance, this algorithm "
54 "can be used to extract the first or last vertices in the geometry. The attributes associated "
55 "to each point are the same ones associated to the feature that the point belongs to." ) +
56 QStringLiteral(
"\n\n" ) +
57 QObject::tr(
"The vertex indices parameter accepts a comma separated string specifying the indices of the "
58 "vertices to extract. The first vertex corresponds to an index of 0, the second vertex has an "
59 "index of 1, etc. Negative indices can be used to find vertices at the end of the geometry, "
60 "e.g., an index of -1 corresponds to the last vertex, -2 corresponds to the second last vertex, etc." ) +
61 QStringLiteral(
"\n\n" ) +
62 QObject::tr(
"Additional fields are added to the points indicating the specific vertex position (e.g., 0, -1, etc), "
63 "the original vertex index, the vertex’s part and its index within the part (as well as its ring for "
64 "polygons), distance along the original geometry and bisector angle of vertex for the original geometry." );
72QString QgsExtractSpecificVerticesAlgorithm::outputName()
const
74 return QObject::tr(
"Vertices" );
77QgsExtractSpecificVerticesAlgorithm *QgsExtractSpecificVerticesAlgorithm::createInstance()
const
79 return new QgsExtractSpecificVerticesAlgorithm();
87QgsFields QgsExtractSpecificVerticesAlgorithm::outputFields(
const QgsFields &inputFields )
const
90 outputFields.
append(
QgsField( QStringLiteral(
"vertex_pos" ), QMetaType::Type::Int ) );
91 outputFields.
append(
QgsField( QStringLiteral(
"vertex_index" ), QMetaType::Type::Int ) );
92 outputFields.
append(
QgsField( QStringLiteral(
"vertex_part" ), QMetaType::Type::Int ) );
95 outputFields.
append(
QgsField( QStringLiteral(
"vertex_part_ring" ), QMetaType::Type::Int ) );
97 outputFields.
append(
QgsField( QStringLiteral(
"vertex_part_index" ), QMetaType::Type::Int ) );
98 outputFields.
append(
QgsField( QStringLiteral(
"distance" ), QMetaType::Type::Double ) );
99 outputFields.
append(
QgsField( QStringLiteral(
"angle" ), QMetaType::Type::Double ) );
116 return outputWkbType;
129void QgsExtractSpecificVerticesAlgorithm::initParameters(
const QVariantMap & )
131 addParameter(
new QgsProcessingParameterString( QStringLiteral(
"VERTICES" ), QObject::tr(
"Vertex indices" ), QStringLiteral(
"0" ) ) );
136 std::unique_ptr< QgsProcessingFeatureSource > source( parameterAsSource( parameters, QStringLiteral(
"INPUT" ), context ) );
142 const QString verticesString = parameterAsString( parameters, QStringLiteral(
"VERTICES" ), context );
143 const QStringList verticesList = verticesString.split(
',', Qt::SkipEmptyParts );
144 for (
const QString &vertex : verticesList )
147 const int i = vertex.toInt( &ok );
189 for (
const int vertex : mIndices )
193 vertexIndex = totalVertices + vertex;
197 vertexIndex = vertex;
200 if ( vertexIndex < 0 || vertexIndex >= totalVertices )
216 attrs << vertexId.
ring;
225 outputFeatures << outFeature;
229 return outputFeatures;
ProcessingSourceType
Processing data source types.
@ VectorPoint
Vector point 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.
QFlags< ProcessingFeatureSourceFlag > ProcessingFeatureSourceFlags
Flags which control how QgsProcessingFeatureSource fetches features.
virtual int nCoordinates() const
Returns the number of nodes contained in the geometry.
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.
void clearGeometry()
Removes any geometry associated with the feature.
void setGeometry(const QgsGeometry &geometry)
Set the feature's geometry.
Encapsulate a field in an attribute table or data source.
Container of fields for a vector layer.
bool append(const QgsField &field, Qgis::FieldOrigin origin=Qgis::FieldOrigin::Provider, int originIndex=-1)
Appends a field.
A geometry is the spatial representation of a feature.
bool vertexIdFromVertexNr(int number, QgsVertexId &id) const
Calculates the vertex ID from a vertex number.
QgsPoint vertexAt(int atVertex) const
Returns coordinates of a vertex.
const QgsAbstractGeometry * constGet() const
Returns a non-modifiable (const) reference to the underlying abstract geometry primitive.
bool isEmpty() const
Returns true if the geometry is empty (eg a linestring with no vertices, or a collection with no geom...
double distanceToVertex(int vertex) const
Returns the distance along this geometry from its first vertex to the specified vertex.
double angleAtVertex(int vertex) const
Returns the bisector angle for this geometry at the specified vertex.
Point geometry type, with support for z-dimension and m-values.
QgsPoint * clone() const override
Clones the geometry by performing a deep copy.
Contains information about the context in which a processing algorithm is executed.
Custom exception class for processing related exceptions.
Base class for providing feedback from a processing algorithm.
A string parameter for processing algorithms.
static Qgis::GeometryType geometryType(Qgis::WkbType type)
Returns the geometry type for a WKB type, e.g., both MultiPolygon and CurvePolygon would have a Polyg...
static Qgis::WkbType addM(Qgis::WkbType type)
Adds the m dimension to a WKB type and returns the new type.
static Qgis::WkbType addZ(Qgis::WkbType type)
Adds the z dimension to a WKB type and returns the new type.
static bool hasZ(Qgis::WkbType type)
Tests whether a WKB type contains the z-dimension.
static bool hasM(Qgis::WkbType type)
Tests whether a WKB type contains m values.
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)
QList< QgsFeature > QgsFeatureList
Utility class for identifying a unique vertex within a geometry.