QGIS API Documentation 3.28.0-Firenze (ed3ad0430f)
qgsalgorithmdensifygeometriesbycount.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsalgorithmdensifygeometries.cpp
3 ---------------------
4 begin : October 2019
5 copyright : (C) 2019 by Clemens Raffler
6 email : clemens dot raffler at gmail dot com
7 ***************************************************************************/
8
9/***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17
18
20
22
23QString QgsDensifyGeometriesByCountAlgorithm::name() const
24{
25 return QStringLiteral( "densifygeometries" );
26}
27
28QString QgsDensifyGeometriesByCountAlgorithm::displayName() const
29{
30 return QObject::tr( "Densify by count" );
31}
32
33QStringList QgsDensifyGeometriesByCountAlgorithm::tags() const
34{
35 return QObject::tr( "add,vertex,vertices,points,nodes" ).split( ',' );
36}
37
38QString QgsDensifyGeometriesByCountAlgorithm::group() const
39{
40 return QObject::tr( "Vector geometry" );
41}
42
43QString QgsDensifyGeometriesByCountAlgorithm::groupId() const
44{
45 return QStringLiteral( "vectorgeometry" );
46}
47
48QString QgsDensifyGeometriesByCountAlgorithm::shortHelpString() const
49{
50 return QObject::tr( "This algorithm takes a polygon or line layer "
51 "and generates a new one in which the geometries "
52 "have a larger number of vertices than the "
53 "original one.\n\n If the geometries have z or m values "
54 "present then these will be linearly interpolated "
55 "at the added nodes.\n\n The number of new vertices to "
56 "add to each feature geometry is specified "
57 "as an input parameter." );
58}
59
60QString QgsDensifyGeometriesByCountAlgorithm::shortDescription() const
61{
62 return QObject::tr( "Creates a densified version of geometries." );
63}
64
65QgsDensifyGeometriesByCountAlgorithm *QgsDensifyGeometriesByCountAlgorithm::createInstance() const
66{
67 return new QgsDensifyGeometriesByCountAlgorithm;
68
69}
70
71QList<int> QgsDensifyGeometriesByCountAlgorithm::inputLayerTypes() const
72{
74}
75
76void QgsDensifyGeometriesByCountAlgorithm::initParameters( const QVariantMap &configuration )
77{
78 Q_UNUSED( configuration )
79 std::unique_ptr<QgsProcessingParameterNumber> verticesCnt = std::make_unique<QgsProcessingParameterNumber>( QStringLiteral( "VERTICES" ),
80 QObject::tr( "Number of vertices to add" ),
82 1, false, 1, 10000000 );
83 verticesCnt->setIsDynamic( true );
84 verticesCnt->setDynamicPropertyDefinition( QgsPropertyDefinition( QStringLiteral( "VerticesCount" ), QObject::tr( "Vertices count" ), QgsPropertyDefinition::IntegerPositive ) );
85 verticesCnt->setDynamicLayerParameterName( QStringLiteral( "INPUT" ) );
86 addParameter( verticesCnt.release() );
87}
88
89QString QgsDensifyGeometriesByCountAlgorithm::outputName() const
90{
91 return QObject::tr( "Densified" );
92}
93
94bool QgsDensifyGeometriesByCountAlgorithm::prepareAlgorithm( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback )
95{
96 Q_UNUSED( feedback )
97 mVerticesCnt = parameterAsInt( parameters, QStringLiteral( "VERTICES" ), context );
98
99 mDynamicVerticesCnt = QgsProcessingParameters::isDynamic( parameters, QStringLiteral( "VERTICES" ) );
100 if ( mDynamicVerticesCnt )
101 mVerticesCntProperty = parameters.value( QStringLiteral( "VERTICES" ) ).value< QgsProperty >();
102
103 return true;
104}
105
106QgsFeatureList QgsDensifyGeometriesByCountAlgorithm::processFeature( const QgsFeature &feature, QgsProcessingContext &context, QgsProcessingFeedback *feedback )
107{
108 Q_UNUSED( context )
109 Q_UNUSED( feedback )
110
111 QgsFeature densifiedFeature = feature;
112
113 if ( feature.hasGeometry() )
114 {
115 int verticesCnt = mVerticesCnt;
116 if ( mDynamicVerticesCnt )
117 verticesCnt = mVerticesCntProperty.valueAsInt( context.expressionContext(), verticesCnt );
118
119 if ( verticesCnt > 0 )
120 densifiedFeature.setGeometry( feature.geometry().densifyByCount( verticesCnt ) );
121 }
122
123 return QgsFeatureList() << densifiedFeature;
124}
125
126
127
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition: qgsfeature.h:56
QgsGeometry geometry
Definition: qgsfeature.h:67
bool hasGeometry() const
Returns true if the feature has an associated geometry.
Definition: qgsfeature.cpp:233
void setGeometry(const QgsGeometry &geometry)
Set the feature's geometry.
Definition: qgsfeature.cpp:170
QgsGeometry densifyByCount(int extraNodesPerSegment) const
Returns a copy of the geometry which has been densified by adding the specified number of extra nodes...
Contains information about the context in which a processing algorithm is executed.
QgsExpressionContext & expressionContext()
Returns the expression context.
Base class for providing feedback from a processing algorithm.
static bool isDynamic(const QVariantMap &parameters, const QString &name)
Returns true if the parameter with matching name is a dynamic parameter, and must be evaluated once f...
@ TypeVectorLine
Vector line layers.
Definition: qgsprocessing.h:50
@ TypeVectorPolygon
Vector polygon layers.
Definition: qgsprocessing.h:51
Definition for a property.
Definition: qgsproperty.h:46
@ IntegerPositive
Positive integer values (including 0)
Definition: qgsproperty.h:54
A store for object properties.
Definition: qgsproperty.h:230
QList< QgsFeature > QgsFeatureList
Definition: qgsfeature.h:922