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 line or polygon layer and generates a point layer with points "
53 "representing specific vertices in the input lines or polygons. 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 line or polygon 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." );
67QString QgsExtractSpecificVerticesAlgorithm::outputName()
const
69 return QObject::tr(
"Vertices" );
72QgsExtractSpecificVerticesAlgorithm *QgsExtractSpecificVerticesAlgorithm::createInstance()
const
74 return new QgsExtractSpecificVerticesAlgorithm();
82QgsFields QgsExtractSpecificVerticesAlgorithm::outputFields(
const QgsFields &inputFields )
const
85 outputFields.
append(
QgsField( QStringLiteral(
"vertex_pos" ), QVariant::Int ) );
86 outputFields.
append(
QgsField( QStringLiteral(
"vertex_index" ), QVariant::Int ) );
87 outputFields.
append(
QgsField( QStringLiteral(
"vertex_part" ), QVariant::Int ) );
90 outputFields.
append(
QgsField( QStringLiteral(
"vertex_part_ring" ), QVariant::Int ) );
92 outputFields.
append(
QgsField( QStringLiteral(
"vertex_part_index" ), QVariant::Int ) );
93 outputFields.
append(
QgsField( QStringLiteral(
"distance" ), QVariant::Double ) );
94 outputFields.
append(
QgsField( QStringLiteral(
"angle" ), QVariant::Double ) );
111 return outputWkbType;
119QgsFeatureSink::SinkFlags QgsExtractSpecificVerticesAlgorithm::sinkFlags()
const
124void QgsExtractSpecificVerticesAlgorithm::initParameters(
const QVariantMap & )
126 addParameter(
new QgsProcessingParameterString( QStringLiteral(
"VERTICES" ), QObject::tr(
"Vertex indices" ), QStringLiteral(
"0" ) ) );
131 std::unique_ptr< QgsProcessingFeatureSource > source( parameterAsSource( parameters, QStringLiteral(
"INPUT" ), context ) );
134 const QString verticesString = parameterAsString( parameters, QStringLiteral(
"VERTICES" ), context );
135#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
136 const QStringList verticesList = verticesString.split(
',', QString::SkipEmptyParts );
138 const QStringList verticesList = verticesString.split(
',', Qt::SkipEmptyParts );
140 for (
const QString &vertex : verticesList )
143 const int i = vertex.toInt( &ok );
184 for (
const int vertex : mIndices )
188 vertexIndex = totalVertices + vertex;
192 vertexIndex = vertex;
195 if ( vertexIndex < 0 || vertexIndex >= totalVertices )
211 attrs << vertexId.
ring;
220 outputFeatures << outFeature;
224 return outputFeatures;
WkbType
The WKB type describes the number of dimensions a geometry has.
virtual int nCoordinates() const
Returns the number of nodes contained in the geometry.
@ 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 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, FieldOrigin origin=OriginProvider, int originIndex=-1)
Appends a field. The field must have unique name, otherwise it is rejected (returns false)
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.
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.
Flag
Flags controlling how QgsProcessingFeatureSource fetches features.
@ FlagSkipGeometryValidityChecks
Invalid geometry checks should always be skipped. This flag can be useful for algorithms which always...
Base class for providing feedback from a processing algorithm.
A string parameter for processing algorithms.
SourceType
Data source types enum.
@ TypeVectorPoint
Vector point layers.
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.