QGIS API Documentation 3.41.0-Master (57ec4277f5e)
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
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
65QList<int> QgsDensifyGeometriesByIntervalAlgorithm::inputLayerTypes() const
66{
67 return QList<int>() << static_cast<int>( Qgis::ProcessingSourceType::VectorLine ) << static_cast<int>( Qgis::ProcessingSourceType::VectorPolygon );
68}
69
70void QgsDensifyGeometriesByIntervalAlgorithm::initParameters( const QVariantMap &configuration )
71{
72 Q_UNUSED( configuration )
73 std::unique_ptr<QgsProcessingParameterDistance> interval = std::make_unique<QgsProcessingParameterDistance>( QStringLiteral( "INTERVAL" ), QObject::tr( "Interval between vertices to add" ), 1, QStringLiteral( "INPUT" ), false, 0, 10000000 );
74 interval->setIsDynamic( true );
75 interval->setDynamicPropertyDefinition( QgsPropertyDefinition( QStringLiteral( "Interval" ), QObject::tr( "Interval" ), QgsPropertyDefinition::DoublePositive ) );
76 interval->setDynamicLayerParameterName( QStringLiteral( "INPUT" ) );
77 addParameter( interval.release() );
78}
79
80QString QgsDensifyGeometriesByIntervalAlgorithm::outputName() const
81{
82 return QObject::tr( "Densified" );
83}
84
85QgsFeatureList QgsDensifyGeometriesByIntervalAlgorithm::processFeature( const QgsFeature &feature, QgsProcessingContext &context, QgsProcessingFeedback *feedback )
86{
87 Q_UNUSED( context )
88 Q_UNUSED( feedback )
89 QgsFeature modifiedFeature = feature;
90
91 double interval = mInterval;
92 if ( mDynamicInterval )
93 interval = mIntervalProperty.valueAsDouble( context.expressionContext(), interval );
94
95 if ( feature.hasGeometry() )
96 modifiedFeature.setGeometry( feature.geometry().densifyByDistance( interval ) );
97
98 return QgsFeatureList() << modifiedFeature;
99}
100
101bool QgsDensifyGeometriesByIntervalAlgorithm::prepareAlgorithm( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback )
102{
103 Q_UNUSED( feedback )
104 mInterval = parameterAsDouble( parameters, QStringLiteral( "INTERVAL" ), context );
105
106 mDynamicInterval = QgsProcessingParameters::isDynamic( parameters, QStringLiteral( "INTERVAL" ) );
107 if ( mDynamicInterval )
108 mIntervalProperty = parameters.value( QStringLiteral( "INTERVAL" ) ).value<QgsProperty>();
109
110 return true;
111}
112
@ 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 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:45
@ DoublePositive
Positive double value (including 0)
Definition qgsproperty.h:56
A store for object properties.
QList< QgsFeature > QgsFeatureList