22using namespace Qt::StringLiterals;
26QString QgsSmoothAlgorithm::name()
const
28 return u
"smoothgeometry"_s;
31QString QgsSmoothAlgorithm::displayName()
const
33 return QObject::tr(
"Smooth" );
36QStringList QgsSmoothAlgorithm::tags()
const
38 return QObject::tr(
"smooth,curve,generalize,round,bend,corners" ).split(
',' );
41QString QgsSmoothAlgorithm::group()
const
43 return QObject::tr(
"Vector geometry" );
46QString QgsSmoothAlgorithm::groupId()
const
48 return u
"vectorgeometry"_s;
51QString QgsSmoothAlgorithm::outputName()
const
53 return QObject::tr(
"Smoothed" );
56QString QgsSmoothAlgorithm::shortHelpString()
const
58 return QObject::tr(
"This algorithm smooths the geometries in a line or polygon layer. It creates a new layer with the "
59 "same features as the ones in the input layer, but with geometries containing a higher number of vertices "
60 "and corners in the geometries smoothed out.\n\n"
61 "The iterations parameter dictates how many smoothing iterations will be applied to each "
62 "geometry. A higher number of iterations results in smoother geometries with the cost of "
63 "greater number of nodes in the geometries.\n\n"
64 "The offset parameter controls how \"tightly\" the smoothed geometries follow the original geometries. "
65 "Smaller values results in a tighter fit, and larger values will create a looser fit.\n\n"
66 "The maximum angle parameter can be used to prevent smoothing of "
67 "nodes with large angles. Any node where the angle of the segments to either "
68 "side is larger than this will not be smoothed. For example, setting the maximum "
69 "angle to 90 degrees or lower would preserve right angles in the geometry.\n\n"
70 "If input geometries contain Z or M values, these will also be smoothed and the output "
71 "geometry will retain the same dimensionality as the input geometry." );
74QString QgsSmoothAlgorithm::shortDescription()
const
76 return QObject::tr(
"Smooths the geometries in a line or polygon layer by adding vertices and rounding corners." );
79QgsSmoothAlgorithm *QgsSmoothAlgorithm::createInstance()
const
81 return new QgsSmoothAlgorithm();
84QList<int> QgsSmoothAlgorithm::inputLayerTypes()
const
89void QgsSmoothAlgorithm::initParameters(
const QVariantMap & )
92 iterations->setIsDynamic(
true );
94 iterations->setDynamicLayerParameterName( u
"INPUT"_s );
95 addParameter( iterations.release() );
98 offset->setIsDynamic(
true );
100 offset->setDynamicLayerParameterName( u
"INPUT"_s );
101 addParameter( offset.release() );
104 maxAngle->setIsDynamic(
true );
106 maxAngle->setDynamicLayerParameterName( u
"INPUT"_s );
107 addParameter( maxAngle.release() );
112 mIterations = parameterAsInt( parameters, u
"ITERATIONS"_s, context );
114 if ( mDynamicIterations )
115 mIterationsProperty = parameters.value( u
"ITERATIONS"_s ).value<
QgsProperty>();
117 mOffset = parameterAsDouble( parameters, u
"OFFSET"_s, context );
119 if ( mDynamicOffset )
120 mOffsetProperty = parameters.value( u
"OFFSET"_s ).value<
QgsProperty>();
122 mMaxAngle = parameterAsDouble( parameters, u
"MAX_ANGLE"_s, context );
124 if ( mDynamicMaxAngle )
125 mMaxAngleProperty = parameters.value( u
"MAX_ANGLE"_s ).value<
QgsProperty>();
135 int iterations = mIterations;
136 if ( mDynamicIterations )
137 iterations = mIterationsProperty.valueAsInt( context.
expressionContext(), iterations );
139 double offset = mOffset;
140 if ( mDynamicOffset )
143 double maxAngle = mMaxAngle;
144 if ( mDynamicMaxAngle )
148 if ( outputGeometry.
isNull() )
150 feedback->
reportError( QObject::tr(
"Error smoothing geometry %1" ).arg( feature.
id() ) );
@ VectorPolygon
Vector polygon layers.
@ VectorLine
Vector line layers.
@ SkipGeometryValidityChecks
Invalid geometry checks should always be skipped. This flag can be useful for algorithms which always...
QFlags< ProcessingFeatureSourceFlag > ProcessingFeatureSourceFlags
Flags which control how QgsProcessingFeatureSource fetches features.
@ Double
Double/float values.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
bool hasGeometry() const
Returns true if the feature has an associated geometry.
void setGeometry(const QgsGeometry &geometry)
Set the feature's geometry.
A geometry is the spatial representation of a feature.
QgsGeometry smooth(unsigned int iterations=1, double offset=0.25, double minimumDistance=-1.0, double maxAngle=180.0) const
Smooths a geometry by rounding off corners using the Chaikin algorithm.
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.
virtual void reportError(const QString &error, bool fatalError=false)
Reports that the algorithm encountered an error while executing.
static bool isDynamic(const QVariantMap ¶meters, 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.
@ Double0To1
Double value between 0-1 (inclusive).
@ IntegerPositiveGreaterZero
Non-zero positive integer values.
@ Rotation
Rotation (value between 0-360 degrees).
A store for object properties.
double valueAsDouble(const QgsExpressionContext &context, double defaultValue=0.0, bool *ok=nullptr) const
Calculates the current value of the property and interprets it as a double.
QList< QgsFeature > QgsFeatureList