22QString QgsSmoothAlgorithm::name()
const
24 return QStringLiteral(
"smoothgeometry" );
27QString QgsSmoothAlgorithm::displayName()
const
29 return QObject::tr(
"Smooth" );
32QStringList QgsSmoothAlgorithm::tags()
const
34 return QObject::tr(
"smooth,curve,generalize,round,bend,corners" ).split(
',' );
37QString QgsSmoothAlgorithm::group()
const
39 return QObject::tr(
"Vector geometry" );
42QString QgsSmoothAlgorithm::groupId()
const
44 return QStringLiteral(
"vectorgeometry" );
47QString QgsSmoothAlgorithm::outputName()
const
49 return QObject::tr(
"Smoothed" );
52QString QgsSmoothAlgorithm::shortHelpString()
const
54 return QObject::tr(
"This algorithm smooths the geometries in a line or polygon layer. It creates a new layer with the "
55 "same features as the ones in the input layer, but with geometries containing a higher number of vertices "
56 "and corners in the geometries smoothed out.\n\n"
57 "The iterations parameter dictates how many smoothing iterations will be applied to each "
58 "geometry. A higher number of iterations results in smoother geometries with the cost of "
59 "greater number of nodes in the geometries.\n\n"
60 "The offset parameter controls how \"tightly\" the smoothed geometries follow the original geometries. "
61 "Smaller values results in a tighter fit, and larger values will create a looser fit.\n\n"
62 "The maximum angle parameter can be used to prevent smoothing of "
63 "nodes with large angles. Any node where the angle of the segments to either "
64 "side is larger than this will not be smoothed. For example, setting the maximum "
65 "angle to 90 degrees or lower would preserve right angles in the geometry.\n\n"
66 "If input geometries contain Z or M values, these will also be smoothed and the output "
67 "geometry will retain the same dimensionality as the input geometry." );
70QgsSmoothAlgorithm *QgsSmoothAlgorithm::createInstance()
const
72 return new QgsSmoothAlgorithm();
75QList<int> QgsSmoothAlgorithm::inputLayerTypes()
const
80void QgsSmoothAlgorithm::initParameters(
const QVariantMap & )
82 std::unique_ptr< QgsProcessingParameterNumber > iterations = std::make_unique< QgsProcessingParameterNumber >( QStringLiteral(
"ITERATIONS" ),
85 iterations->setIsDynamic(
true );
87 iterations->setDynamicLayerParameterName( QStringLiteral(
"INPUT" ) );
88 addParameter( iterations.release() );
90 std::unique_ptr< QgsProcessingParameterNumber > offset = std::make_unique< QgsProcessingParameterNumber >( QStringLiteral(
"OFFSET" ),
92 0.25,
false, 0.0, 0.5 );
93 offset->setIsDynamic(
true );
95 offset->setDynamicLayerParameterName( QStringLiteral(
"INPUT" ) );
96 addParameter( offset.release() );
98 std::unique_ptr< QgsProcessingParameterNumber > maxAngle = std::make_unique< QgsProcessingParameterNumber >( QStringLiteral(
"MAX_ANGLE" ),
100 180.0,
false, 0.0, 180.0 );
101 maxAngle->setIsDynamic(
true );
103 maxAngle->setDynamicLayerParameterName( QStringLiteral(
"INPUT" ) );
104 addParameter( maxAngle.release() );
109 mIterations = parameterAsInt( parameters, QStringLiteral(
"ITERATIONS" ), context );
111 if ( mDynamicIterations )
112 mIterationsProperty = parameters.value( QStringLiteral(
"ITERATIONS" ) ).value<
QgsProperty >();
114 mOffset = parameterAsDouble( parameters, QStringLiteral(
"OFFSET" ), context );
116 if ( mDynamicOffset )
117 mOffsetProperty = parameters.value( QStringLiteral(
"OFFSET" ) ).value<
QgsProperty >();
119 mMaxAngle = parameterAsDouble( parameters, QStringLiteral(
"MAX_ANGLE" ), context );
121 if ( mDynamicMaxAngle )
122 mMaxAngleProperty = parameters.value( QStringLiteral(
"MAX_ANGLE" ) ).value<
QgsProperty >();
132 int iterations = mIterations;
133 if ( mDynamicIterations )
134 iterations = mIterationsProperty.valueAsInt( context.
expressionContext(), iterations );
136 double offset = mOffset;
137 if ( mDynamicOffset )
140 double maxAngle = mMaxAngle;
141 if ( mDynamicMaxAngle )
145 if ( outputGeometry.
isNull() )
147 feedback->
reportError( QObject::tr(
"Error smoothing geometry %1" ).arg( feature.
id() ) );
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.
Flag
Flags controlling how QgsProcessingFeatureSource fetches features.
@ FlagSkipGeometryValidityChecks
Invalid geometry checks should always be skipped. This flag can be useful for algorithms which always...
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.
@ Double
Double/float values.
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...
@ TypeVectorLine
Vector line layers.
@ TypeVectorPolygon
Vector polygon layers.
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