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" ), QObject::tr(
"Iterations" ),
Qgis::ProcessingNumberParameterType::Integer, 1,
false, 1, 10 );
83 iterations->setIsDynamic(
true );
85 iterations->setDynamicLayerParameterName( QStringLiteral(
"INPUT" ) );
86 addParameter( iterations.release() );
88 std::unique_ptr<QgsProcessingParameterNumber> offset = std::make_unique<QgsProcessingParameterNumber>( QStringLiteral(
"OFFSET" ), QObject::tr(
"Offset" ),
Qgis::ProcessingNumberParameterType::Double, 0.25,
false, 0.0, 0.5 );
89 offset->setIsDynamic(
true );
91 offset->setDynamicLayerParameterName( QStringLiteral(
"INPUT" ) );
92 addParameter( offset.release() );
94 std::unique_ptr<QgsProcessingParameterNumber> maxAngle = std::make_unique<QgsProcessingParameterNumber>( QStringLiteral(
"MAX_ANGLE" ), QObject::tr(
"Maximum node angle to smooth" ),
Qgis::ProcessingNumberParameterType::Double, 180.0,
false, 0.0, 180.0 );
95 maxAngle->setIsDynamic(
true );
97 maxAngle->setDynamicLayerParameterName( QStringLiteral(
"INPUT" ) );
98 addParameter( maxAngle.release() );
103 mIterations = parameterAsInt( parameters, QStringLiteral(
"ITERATIONS" ), context );
105 if ( mDynamicIterations )
106 mIterationsProperty = parameters.value( QStringLiteral(
"ITERATIONS" ) ).value<
QgsProperty>();
108 mOffset = parameterAsDouble( parameters, QStringLiteral(
"OFFSET" ), context );
110 if ( mDynamicOffset )
111 mOffsetProperty = parameters.value( QStringLiteral(
"OFFSET" ) ).value<
QgsProperty>();
113 mMaxAngle = parameterAsDouble( parameters, QStringLiteral(
"MAX_ANGLE" ), context );
115 if ( mDynamicMaxAngle )
116 mMaxAngleProperty = parameters.value( QStringLiteral(
"MAX_ANGLE" ) ).value<
QgsProperty>();
126 int iterations = mIterations;
127 if ( mDynamicIterations )
128 iterations = mIterationsProperty.valueAsInt( context.
expressionContext(), iterations );
130 double offset = mOffset;
131 if ( mDynamicOffset )
134 double maxAngle = mMaxAngle;
135 if ( mDynamicMaxAngle )
139 if ( outputGeometry.
isNull() )
141 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