25using namespace Qt::StringLiterals;
29QString QgsExtractSpecificVerticesAlgorithm::name()
const
31 return u
"extractspecificvertices"_s;
34QString QgsExtractSpecificVerticesAlgorithm::displayName()
const
36 return QObject::tr(
"Extract specific vertices" );
39QStringList QgsExtractSpecificVerticesAlgorithm::tags()
const
41 return QObject::tr(
"points,vertex,nodes" ).split(
',' );
44QString QgsExtractSpecificVerticesAlgorithm::group()
const
46 return QObject::tr(
"Vector geometry" );
49QString QgsExtractSpecificVerticesAlgorithm::groupId()
const
51 return u
"vectorgeometry"_s;
54QString QgsExtractSpecificVerticesAlgorithm::shortHelpString()
const
56 return QObject::tr(
"This algorithm takes a vector layer and generates a point layer with points "
57 "representing specific vertices in the input geometries. For instance, this algorithm "
58 "can be used to extract the first or last vertices in the geometry. The attributes associated "
59 "to each point are the same ones associated to the feature that the point belongs to." )
60 + u
"\n\n"_s + QObject::tr(
"The vertex indices parameter accepts a comma separated string specifying the indices of the "
61 "vertices to extract. The first vertex corresponds to an index of 0, the second vertex has an "
62 "index of 1, etc. Negative indices can be used to find vertices at the end of the geometry, "
63 "e.g., an index of -1 corresponds to the last vertex, -2 corresponds to the second last vertex, etc." )
64 + u
"\n\n"_s + QObject::tr(
"Additional fields are added to the points indicating the specific vertex position (e.g., 0, -1, etc), "
65 "the original vertex index, the vertex’s part and its index within the part (as well as its ring for "
66 "polygons), distance along the original geometry and bisector angle of vertex for the original geometry." );
69QString QgsExtractSpecificVerticesAlgorithm::shortDescription()
const
71 return QObject::tr(
"Generates a point layer with points representing specific vertices in the input geometries." );
79QString QgsExtractSpecificVerticesAlgorithm::outputName()
const
81 return QObject::tr(
"Vertices" );
84QgsExtractSpecificVerticesAlgorithm *QgsExtractSpecificVerticesAlgorithm::createInstance()
const
86 return new QgsExtractSpecificVerticesAlgorithm();
94QgsFields QgsExtractSpecificVerticesAlgorithm::outputFields(
const QgsFields &inputFields )
const
97 newFields.
append(
QgsField( u
"vertex_pos"_s, QMetaType::Type::Int ) );
98 newFields.
append(
QgsField( u
"vertex_index"_s, QMetaType::Type::Int ) );
99 newFields.
append(
QgsField( u
"vertex_part"_s, QMetaType::Type::Int ) );
102 newFields.
append(
QgsField( u
"vertex_part_ring"_s, QMetaType::Type::Int ) );
104 newFields.
append(
QgsField( u
"vertex_part_index"_s, QMetaType::Type::Int ) );
105 newFields.
append(
QgsField( u
"distance"_s, QMetaType::Type::Double ) );
106 newFields.
append(
QgsField( u
"angle"_s, QMetaType::Type::Double ) );
123 return outputWkbType;
136void QgsExtractSpecificVerticesAlgorithm::initParameters(
const QVariantMap & )
143 std::unique_ptr<QgsProcessingFeatureSource> source( parameterAsSource( parameters, u
"INPUT"_s, context ) );
149 const QString verticesString = parameterAsString( parameters, u
"VERTICES"_s, context );
150 const QStringList verticesList = verticesString.split(
',', Qt::SkipEmptyParts );
151 for (
const QString &vertex : verticesList )
154 const int i = vertex.toInt( &ok );
196 for (
const int vertex : mIndices )
200 vertexIndex = totalVertices + vertex;
204 vertexIndex = vertex;
207 if ( vertexIndex < 0 || vertexIndex >= totalVertices )
223 attrs << vertexId.
ring;
232 outputFeatures << outFeature;
236 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 QgsFields combineFields(const QgsFields &fieldsA, const QgsFields &fieldsB, const QString &fieldsBPrefix=QString())
Combines two field lists, avoiding duplicate field names (in a case-insensitive manner).
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 Q_INVOKABLE bool hasZ(Qgis::WkbType type)
Tests whether a WKB type contains the z-dimension.
static Q_INVOKABLE 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.