QGIS API Documentation 3.43.0-Master (a93bf8b6462)
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
6 email : matthias@opengis.ch
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( "This algorithm takes a polygon or line layer and generates a new one "
51 "in which the geometries have a larger number of vertices than the original one.\n\n"
52 "Geometries are densified by adding additional vertices on "
53 "edges that have a maximum distance of the interval parameter "
54 "in map units." );
55}
56
57QString QgsDensifyGeometriesByIntervalAlgorithm::shortDescription() const
58{
59 return QObject::tr( "Creates a densified version of geometries by setting a maximum distance for segments." );
60}
61
62QgsDensifyGeometriesByIntervalAlgorithm *QgsDensifyGeometriesByIntervalAlgorithm::createInstance() const
63{
64 return new QgsDensifyGeometriesByIntervalAlgorithm;
65}
66
67QList<int> QgsDensifyGeometriesByIntervalAlgorithm::inputLayerTypes() const
68{
69 return QList<int>() << static_cast<int>( Qgis::ProcessingSourceType::VectorLine ) << static_cast<int>( Qgis::ProcessingSourceType::VectorPolygon );
70}
71
72void QgsDensifyGeometriesByIntervalAlgorithm::initParameters( const QVariantMap &configuration )
73{
74 Q_UNUSED( configuration )
75 auto interval = std::make_unique<QgsProcessingParameterDistance>( QStringLiteral( "INTERVAL" ), QObject::tr( "Interval between vertices to add" ), 1, QStringLiteral( "INPUT" ), false, 0, 10000000 );
76 interval->setIsDynamic( true );
77 interval->setDynamicPropertyDefinition( QgsPropertyDefinition( QStringLiteral( "Interval" ), QObject::tr( "Interval" ), QgsPropertyDefinition::DoublePositive ) );
78 interval->setDynamicLayerParameterName( QStringLiteral( "INPUT" ) );
79 addParameter( interval.release() );
80}
81
82QString QgsDensifyGeometriesByIntervalAlgorithm::outputName() const
83{
84 return QObject::tr( "Densified" );
85}
86
87QgsFeatureList QgsDensifyGeometriesByIntervalAlgorithm::processFeature( const QgsFeature &feature, QgsProcessingContext &context, QgsProcessingFeedback *feedback )
88{
89 Q_UNUSED( context )
90 Q_UNUSED( feedback )
91 QgsFeature modifiedFeature = feature;
92
93 double interval = mInterval;
94 if ( mDynamicInterval )
95 interval = mIntervalProperty.valueAsDouble( context.expressionContext(), interval );
96
97 if ( feature.hasGeometry() )
98 modifiedFeature.setGeometry( feature.geometry().densifyByDistance( interval ) );
99
100 return QgsFeatureList() << modifiedFeature;
101}
102
103bool QgsDensifyGeometriesByIntervalAlgorithm::prepareAlgorithm( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback )
104{
105 Q_UNUSED( feedback )
106 mInterval = parameterAsDouble( parameters, QStringLiteral( "INTERVAL" ), context );
107
108 mDynamicInterval = QgsProcessingParameters::isDynamic( parameters, QStringLiteral( "INTERVAL" ) );
109 if ( mDynamicInterval )
110 mIntervalProperty = parameters.value( QStringLiteral( "INTERVAL" ) ).value<QgsProperty>();
111
112 return true;
113}
114
@ 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