QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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 : [email protected]
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 
23 QString QgsDensifyGeometriesByIntervalAlgorithm::name() const
24 {
25  return QStringLiteral( "densifygeometriesgivenaninterval" );
26 }
27 
28 QString QgsDensifyGeometriesByIntervalAlgorithm::displayName() const
29 {
30  return QObject::tr( "Densify by interval" );
31 }
32 
33 QStringList QgsDensifyGeometriesByIntervalAlgorithm::tags() const
34 {
35  return QObject::tr( "add,vertex,vertices,points,nodes" ).split( ',' );
36 }
37 
38 QString QgsDensifyGeometriesByIntervalAlgorithm::group() const
39 {
40  return QObject::tr( "Vector geometry" );
41 }
42 
43 QString QgsDensifyGeometriesByIntervalAlgorithm::groupId() const
44 {
45  return QStringLiteral( "vectorgeometry" );
46 }
47 
48 QString 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 
55 QString QgsDensifyGeometriesByIntervalAlgorithm::shortDescription() const
56 {
57  return QObject::tr( "Creates a densified version of geometries." );
58 }
59 
60 QgsDensifyGeometriesByIntervalAlgorithm *QgsDensifyGeometriesByIntervalAlgorithm::createInstance() const
61 {
62  return new QgsDensifyGeometriesByIntervalAlgorithm;
63 
64 }
65 
66 QList<int> QgsDensifyGeometriesByIntervalAlgorithm::inputLayerTypes() const
67 {
69 }
70 
71 void 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 
83 QString QgsDensifyGeometriesByIntervalAlgorithm::outputName() const
84 {
85  return QObject::tr( "Densified" );
86 }
87 
88 QgsFeatureList 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 
104 bool 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 
QgsProperty
A store for object properties.
Definition: qgsproperty.h:230
QgsProcessingParameters::isDynamic
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: qgsprocessingparameters.cpp:114
QgsProcessingFeedback
Base class for providing feedback from a processing algorithm.
Definition: qgsprocessingfeedback.h:37
QgsProcessing::TypeVectorPolygon
@ TypeVectorPolygon
Vector polygon layers.
Definition: qgsprocessing.h:51
QgsFeature::geometry
QgsGeometry geometry
Definition: qgsfeature.h:71
QgsProcessing::TypeVectorLine
@ TypeVectorLine
Vector line layers.
Definition: qgsprocessing.h:50
qgsalgorithmdensifygeometriesbyinterval.h
QgsFeature::setGeometry
void setGeometry(const QgsGeometry &geometry)
Set the feature's geometry.
Definition: qgsfeature.cpp:170
QgsProcessingContext
Contains information about the context in which a processing algorithm is executed.
Definition: qgsprocessingcontext.h:46
QgsFeatureList
QList< QgsFeature > QgsFeatureList
Definition: qgsfeature.h:882
QgsGeometry::densifyByDistance
QgsGeometry densifyByDistance(double distance) const
Densifies the geometry by adding regularly placed extra nodes inside each segment so that the maximum...
Definition: qgsgeometry.cpp:2270
QgsPropertyDefinition
Definition for a property.
Definition: qgsproperty.h:46
QgsFeature::hasGeometry
bool hasGeometry() const
Returns true if the feature has an associated geometry.
Definition: qgsfeature.cpp:230
QgsProcessingContext::expressionContext
QgsExpressionContext & expressionContext()
Returns the expression context.
Definition: qgsprocessingcontext.h:149
QgsFeature
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition: qgsfeature.h:55
QgsPropertyDefinition::DoublePositive
@ DoublePositive
Positive double value (including 0)
Definition: qgsproperty.h:58