QGIS API Documentation 3.41.0-Master (d5b93354e9c)
Loading...
Searching...
No Matches
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
70QList<int> QgsDensifyGeometriesByCountAlgorithm::inputLayerTypes() const
71{
72 return QList<int>() << static_cast<int>( Qgis::ProcessingSourceType::VectorLine ) << static_cast<int>( Qgis::ProcessingSourceType::VectorPolygon );
73}
74
75void QgsDensifyGeometriesByCountAlgorithm::initParameters( const QVariantMap &configuration )
76{
77 Q_UNUSED( configuration )
78 std::unique_ptr<QgsProcessingParameterNumber> verticesCnt = std::make_unique<QgsProcessingParameterNumber>( QStringLiteral( "VERTICES" ), QObject::tr( "Number of vertices to add" ), Qgis::ProcessingNumberParameterType::Integer, 1, false, 1, 10000000 );
79 verticesCnt->setIsDynamic( true );
80 verticesCnt->setDynamicPropertyDefinition( QgsPropertyDefinition( QStringLiteral( "VerticesCount" ), QObject::tr( "Vertices count" ), QgsPropertyDefinition::IntegerPositive ) );
81 verticesCnt->setDynamicLayerParameterName( QStringLiteral( "INPUT" ) );
82 addParameter( verticesCnt.release() );
83}
84
85QString QgsDensifyGeometriesByCountAlgorithm::outputName() const
86{
87 return QObject::tr( "Densified" );
88}
89
90bool QgsDensifyGeometriesByCountAlgorithm::prepareAlgorithm( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback )
91{
92 Q_UNUSED( feedback )
93 mVerticesCnt = parameterAsInt( parameters, QStringLiteral( "VERTICES" ), context );
94
95 mDynamicVerticesCnt = QgsProcessingParameters::isDynamic( parameters, QStringLiteral( "VERTICES" ) );
96 if ( mDynamicVerticesCnt )
97 mVerticesCntProperty = parameters.value( QStringLiteral( "VERTICES" ) ).value<QgsProperty>();
98
99 return true;
100}
101
102QgsFeatureList QgsDensifyGeometriesByCountAlgorithm::processFeature( const QgsFeature &feature, QgsProcessingContext &context, QgsProcessingFeedback *feedback )
103{
104 Q_UNUSED( context )
105 Q_UNUSED( feedback )
106
107 QgsFeature densifiedFeature = feature;
108
109 if ( feature.hasGeometry() )
110 {
111 int verticesCnt = mVerticesCnt;
112 if ( mDynamicVerticesCnt )
113 verticesCnt = mVerticesCntProperty.valueAsInt( context.expressionContext(), verticesCnt );
114
115 if ( verticesCnt > 0 )
116 densifiedFeature.setGeometry( feature.geometry().densifyByCount( verticesCnt ) );
117 }
118
119 return QgsFeatureList() << densifiedFeature;
120}
121
122
@ VectorPolygon
Vector polygon layers.
@ VectorLine
Vector line layers.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition qgsfeature.h:58
QgsGeometry geometry
Definition qgsfeature.h:69
bool hasGeometry() const
Returns true if the feature has an associated geometry.
void setGeometry(const QgsGeometry &geometry)
Set the feature's geometry.
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...
Definition for a property.
Definition qgsproperty.h:45
@ IntegerPositive
Positive integer values (including 0)
Definition qgsproperty.h:53
A store for object properties.
QList< QgsFeature > QgsFeatureList