25 QString QgsExtractSpecificVerticesAlgorithm::name()
const 27 return QStringLiteral(
"extractspecificvertices" );
30 QString QgsExtractSpecificVerticesAlgorithm::displayName()
const 32 return QObject::tr(
"Extract specific vertices" );
35 QStringList QgsExtractSpecificVerticesAlgorithm::tags()
const 37 return QObject::tr(
"points,vertex,nodes" ).split(
',' );
40 QString QgsExtractSpecificVerticesAlgorithm::group()
const 42 return QObject::tr(
"Vector geometry" );
45 QString QgsExtractSpecificVerticesAlgorithm::groupId()
const 47 return QStringLiteral(
"vectorgeometry" );
50 QString 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." );
67 QString QgsExtractSpecificVerticesAlgorithm::outputName()
const 69 return QObject::tr(
"Vertices" );
72 QgsExtractSpecificVerticesAlgorithm *QgsExtractSpecificVerticesAlgorithm::createInstance()
const 74 return new QgsExtractSpecificVerticesAlgorithm();
82 QgsFields 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;
119 QgsFeatureSink::SinkFlags QgsExtractSpecificVerticesAlgorithm::sinkFlags()
const 124 void 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 QString verticesString = parameterAsString( parameters, QStringLiteral(
"VERTICES" ), context );
135 const QStringList verticesList = verticesString.split(
',', QString::SkipEmptyParts );
136 for (
const QString &vertex : verticesList )
139 int i = vertex.toInt( &ok );
180 for (
int vertex : mIndices )
184 vertexIndex = totalVertices + vertex;
188 vertexIndex = vertex;
191 if ( vertexIndex < 0 || vertexIndex >= totalVertices )
207 attrs << vertexId.
ring;
216 outputFeatures << outFeature;
220 return outputFeatures;
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...
double angleAtVertex(int vertex) const
Returns the bisector angle for this geometry at the specified vertex.
QList< QgsFeature > QgsFeatureList
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...
double distanceToVertex(int vertex) const
Returns the distance along this geometry from its first vertex to the specified vertex.
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)
This flag indicates, that a primary key field cannot be guaranteed to be unique and the sink should i...
Type
The WKB type describes the number of dimensions a geometry has.
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.
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.
Custom exception class for processing related exceptions.
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) ...
QgsPoint * clone() const override
Clones the geometry by performing a deep copy.
Encapsulate a field in an attribute table or data source.
Point geometry type, with support for z-dimension and m-values.
Flag
Flags controlling how QgsProcessingFeatureSource fetches features.
const QgsAbstractGeometry * constGet() const
Returns a non-modifiable (const) reference to the underlying abstract geometry primitive.
QgsPoint vertexAt(int atVertex) const
Returns coordinates of a vertex.
void setGeometry(const QgsGeometry &geometry)
Set the feature's geometry.
SourceType
Data source types enum.
static bool hasM(Type type)
Tests whether a WKB type contains m values.
bool vertexIdFromVertexNr(int number, QgsVertexId &id) const
Calculates the vertex ID from a vertex number.
virtual int nCoordinates() const
Returns the number of nodes contained in the geometry.
Contains information about the context in which a processing algorithm is executed.
A string parameter for processing algorithms.