QGIS API Documentation 3.28.0-Firenze (ed3ad0430f)
qgsalgorithmdensifygeometriesbyinterval.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsalgorithmdensifygeometries.cpp
3 ---------------------
4 begin : January 2019
5 copyright : (C) 2019 by Matthias Kuhn
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 QgsDensifyGeometriesByIntervalAlgorithm::name() const
24{
25 return QStringLiteral( "densifygeometriesgivenaninterval" );
26}
27
28QString QgsDensifyGeometriesByIntervalAlgorithm::displayName() const
29{
30 return QObject::tr( "Densify by interval" );
31}
32
33QStringList QgsDensifyGeometriesByIntervalAlgorithm::tags() const
34{
35 return QObject::tr( "add,vertex,vertices,points,nodes" ).split( ',' );
36}
37
38QString QgsDensifyGeometriesByIntervalAlgorithm::group() const
39{
40 return QObject::tr( "Vector geometry" );
41}
42
43QString QgsDensifyGeometriesByIntervalAlgorithm::groupId() const
44{
45 return QStringLiteral( "vectorgeometry" );
46}
47
48QString QgsDensifyGeometriesByIntervalAlgorithm::shortHelpString() const
49{
50 return QObject::tr( "Geometries are densified by adding additional vertices on "
51 "edges that have a maximum distance of the interval parameter "
52 "in map units." );
53}
54
55QString QgsDensifyGeometriesByIntervalAlgorithm::shortDescription() const
56{
57 return QObject::tr( "Creates a densified version of geometries." );
58}
59
60QgsDensifyGeometriesByIntervalAlgorithm *QgsDensifyGeometriesByIntervalAlgorithm::createInstance() const
61{
62 return new QgsDensifyGeometriesByIntervalAlgorithm;
63
64}
65
66QList<int> QgsDensifyGeometriesByIntervalAlgorithm::inputLayerTypes() const
67{
69}
70
71void QgsDensifyGeometriesByIntervalAlgorithm::initParameters( const QVariantMap &configuration )
72{
73 Q_UNUSED( configuration )
74 std::unique_ptr<QgsProcessingParameterDistance> interval = std::make_unique<QgsProcessingParameterDistance>( QStringLiteral( "INTERVAL" ),
75 QObject::tr( "Interval between vertices to add" ),
76 1, QStringLiteral( "INPUT" ), false, 0, 10000000 );
77 interval->setIsDynamic( true );
78 interval->setDynamicPropertyDefinition( QgsPropertyDefinition( QStringLiteral( "Interval" ), QObject::tr( "Interval" ), QgsPropertyDefinition::DoublePositive ) );
79 interval->setDynamicLayerParameterName( QStringLiteral( "INPUT" ) );
80 addParameter( interval.release() );
81}
82
83QString QgsDensifyGeometriesByIntervalAlgorithm::outputName() const
84{
85 return QObject::tr( "Densified" );
86}
87
88QgsFeatureList QgsDensifyGeometriesByIntervalAlgorithm::processFeature( const QgsFeature &feature, QgsProcessingContext &context, QgsProcessingFeedback *feedback )
89{
90 Q_UNUSED( context )
91 Q_UNUSED( feedback )
92 QgsFeature modifiedFeature = feature;
93
94 double interval = mInterval;
95 if ( mDynamicInterval )
96 interval = mIntervalProperty.valueAsDouble( context.expressionContext(), interval );
97
98 if ( feature.hasGeometry() )
99 modifiedFeature.setGeometry( feature.geometry().densifyByDistance( interval ) );
100
101 return QgsFeatureList() << modifiedFeature;
102}
103
104bool QgsDensifyGeometriesByIntervalAlgorithm::prepareAlgorithm( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback )
105{
106 Q_UNUSED( feedback )
107 mInterval = parameterAsDouble( parameters, QStringLiteral( "INTERVAL" ), context );
108
109 mDynamicInterval = QgsProcessingParameters::isDynamic( parameters, QStringLiteral( "INTERVAL" ) );
110 if ( mDynamicInterval )
111 mIntervalProperty = parameters.value( QStringLiteral( "INTERVAL" ) ).value< QgsProperty >();
112
113 return true;
114}
115
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 densifyByDistance(double distance) const
Densifies the geometry by adding regularly placed extra nodes inside each segment so that the maximum...
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
@ DoublePositive
Positive double value (including 0)
Definition: qgsproperty.h:57
A store for object properties.
Definition: qgsproperty.h:230
QList< QgsFeature > QgsFeatureList
Definition: qgsfeature.h:922