QGIS API Documentation 3.99.0-Master (09f76ad7019)
Loading...
Searching...
No Matches
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
21#include <QString>
22
23using namespace Qt::StringLiterals;
24
26
27QString QgsDensifyGeometriesByIntervalAlgorithm::name() const
28{
29 return u"densifygeometriesgivenaninterval"_s;
30}
31
32QString QgsDensifyGeometriesByIntervalAlgorithm::displayName() const
33{
34 return QObject::tr( "Densify by interval" );
35}
36
37QStringList QgsDensifyGeometriesByIntervalAlgorithm::tags() const
38{
39 return QObject::tr( "add,vertex,vertices,points,nodes" ).split( ',' );
40}
41
42QString QgsDensifyGeometriesByIntervalAlgorithm::group() const
43{
44 return QObject::tr( "Vector geometry" );
45}
46
47QString QgsDensifyGeometriesByIntervalAlgorithm::groupId() const
48{
49 return u"vectorgeometry"_s;
50}
51
52QString QgsDensifyGeometriesByIntervalAlgorithm::shortHelpString() const
53{
54 return QObject::tr( "This algorithm takes a polygon or line layer and generates a new one "
55 "in which the geometries have a larger number of vertices than the original one.\n\n"
56 "Geometries are densified by adding additional vertices on "
57 "edges that have a maximum distance of the interval parameter "
58 "in map units." );
59}
60
61QString QgsDensifyGeometriesByIntervalAlgorithm::shortDescription() const
62{
63 return QObject::tr( "Creates a densified version of geometries by setting a maximum distance for segments." );
64}
65
66QgsDensifyGeometriesByIntervalAlgorithm *QgsDensifyGeometriesByIntervalAlgorithm::createInstance() const
67{
68 return new QgsDensifyGeometriesByIntervalAlgorithm;
69}
70
71QList<int> QgsDensifyGeometriesByIntervalAlgorithm::inputLayerTypes() const
72{
73 return QList<int>() << static_cast<int>( Qgis::ProcessingSourceType::VectorLine ) << static_cast<int>( Qgis::ProcessingSourceType::VectorPolygon );
74}
75
76void QgsDensifyGeometriesByIntervalAlgorithm::initParameters( const QVariantMap &configuration )
77{
78 Q_UNUSED( configuration )
79 auto interval = std::make_unique<QgsProcessingParameterDistance>( u"INTERVAL"_s, QObject::tr( "Interval between vertices to add" ), 1, u"INPUT"_s, false, 0, 10000000 );
80 interval->setIsDynamic( true );
81 interval->setDynamicPropertyDefinition( QgsPropertyDefinition( u"Interval"_s, QObject::tr( "Interval" ), QgsPropertyDefinition::DoublePositive ) );
82 interval->setDynamicLayerParameterName( u"INPUT"_s );
83 addParameter( interval.release() );
84}
85
86QString QgsDensifyGeometriesByIntervalAlgorithm::outputName() const
87{
88 return QObject::tr( "Densified" );
89}
90
91QgsFeatureList QgsDensifyGeometriesByIntervalAlgorithm::processFeature( const QgsFeature &feature, QgsProcessingContext &context, QgsProcessingFeedback *feedback )
92{
93 Q_UNUSED( context )
94 Q_UNUSED( feedback )
95 QgsFeature modifiedFeature = feature;
96
97 double interval = mInterval;
98 if ( mDynamicInterval )
99 interval = mIntervalProperty.valueAsDouble( context.expressionContext(), interval );
100
101 if ( feature.hasGeometry() )
102 modifiedFeature.setGeometry( feature.geometry().densifyByDistance( interval ) );
103
104 return QgsFeatureList() << modifiedFeature;
105}
106
107bool QgsDensifyGeometriesByIntervalAlgorithm::prepareAlgorithm( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback )
108{
109 Q_UNUSED( feedback )
110 mInterval = parameterAsDouble( parameters, u"INTERVAL"_s, context );
111
112 mDynamicInterval = QgsProcessingParameters::isDynamic( parameters, u"INTERVAL"_s );
113 if ( mDynamicInterval )
114 mIntervalProperty = parameters.value( u"INTERVAL"_s ).value<QgsProperty>();
115
116 return true;
117}
118
@ VectorPolygon
Vector polygon layers.
Definition qgis.h:3607
@ VectorLine
Vector line layers.
Definition qgis.h:3606
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition qgsfeature.h:60
QgsGeometry geometry
Definition qgsfeature.h:71
bool hasGeometry() const
Returns true if the feature has an associated geometry.
void setGeometry(const QgsGeometry &geometry)
Set the feature's geometry.
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...
Definition for a property.
Definition qgsproperty.h:47
@ DoublePositive
Positive double value (including 0).
Definition qgsproperty.h:58
A store for object properties.
QList< QgsFeature > QgsFeatureList