22 QString QgsSmoothAlgorithm::name()
const
24 return QStringLiteral(
"smoothgeometry" );
27 QString QgsSmoothAlgorithm::displayName()
const
29 return QObject::tr(
"Smooth" );
32 QStringList QgsSmoothAlgorithm::tags()
const
34 return QObject::tr(
"smooth,curve,generalize,round,bend,corners" ).split(
',' );
37 QString QgsSmoothAlgorithm::group()
const
39 return QObject::tr(
"Vector geometry" );
42 QString QgsSmoothAlgorithm::groupId()
const
44 return QStringLiteral(
"vectorgeometry" );
47 QString QgsSmoothAlgorithm::outputName()
const
49 return QObject::tr(
"Smoothed" );
57 QString QgsSmoothAlgorithm::shortHelpString()
const
59 return QObject::tr(
"This algorithm smooths the geometries in a line or polygon layer. It creates a new layer with the "
60 "same features as the ones in the input layer, but with geometries containing a higher number of vertices "
61 "and corners in the geometries smoothed out.\n\n"
62 "The iterations parameter dictates how many smoothing iterations will be applied to each "
63 "geometry. A higher number of iterations results in smoother geometries with the cost of "
64 "greater number of nodes in the geometries.\n\n"
65 "The offset parameter controls how \"tightly\" the smoothed geometries follow the original geometries. "
66 "Smaller values results in a tighter fit, and larger values will create a looser fit.\n\n"
67 "The maximum angle parameter can be used to prevent smoothing of "
68 "nodes with large angles. Any node where the angle of the segments to either "
69 "side is larger than this will not be smoothed. For example, setting the maximum "
70 "angle to 90 degrees or lower would preserve right angles in the geometry.\n\n"
71 "If input geometries contain Z or M values, these will also be smoothed and the output "
72 "geometry will retain the same dimensionality as the input geometry." );
75 QgsSmoothAlgorithm *QgsSmoothAlgorithm::createInstance()
const
77 return new QgsSmoothAlgorithm();
80 QList<int> QgsSmoothAlgorithm::inputLayerTypes()
const
85 void QgsSmoothAlgorithm::initParameters(
const QVariantMap & )
87 std::unique_ptr< QgsProcessingParameterNumber > iterations = qgis::make_unique< QgsProcessingParameterNumber >( QStringLiteral(
"ITERATIONS" ),
90 iterations->setIsDynamic(
true );
92 iterations->setDynamicLayerParameterName( QStringLiteral(
"INPUT" ) );
93 addParameter( iterations.release() );
95 std::unique_ptr< QgsProcessingParameterNumber > offset = qgis::make_unique< QgsProcessingParameterNumber >( QStringLiteral(
"OFFSET" ),
97 0.25,
false, 0.0, 0.5 );
98 offset->setIsDynamic(
true );
100 offset->setDynamicLayerParameterName( QStringLiteral(
"INPUT" ) );
101 addParameter( offset.release() );
103 std::unique_ptr< QgsProcessingParameterNumber > maxAngle = qgis::make_unique< QgsProcessingParameterNumber >( QStringLiteral(
"MAX_ANGLE" ),
105 180.0,
false, 0.0, 180.0 );
106 maxAngle->setIsDynamic(
true );
108 maxAngle->setDynamicLayerParameterName( QStringLiteral(
"INPUT" ) );
109 addParameter( maxAngle.release() );
114 mIterations = parameterAsInt( parameters, QStringLiteral(
"ITERATIONS" ), context );
116 if ( mDynamicIterations )
117 mIterationsProperty = parameters.value( QStringLiteral(
"ITERATIONS" ) ).value<
QgsProperty >();
119 mOffset = parameterAsDouble( parameters, QStringLiteral(
"OFFSET" ), context );
121 if ( mDynamicOffset )
122 mOffsetProperty = parameters.value( QStringLiteral(
"OFFSET" ) ).value<
QgsProperty >();
124 mMaxAngle = parameterAsDouble( parameters, QStringLiteral(
"MAX_ANGLE" ), context );
126 if ( mDynamicMaxAngle )
127 mMaxAngleProperty = parameters.value( QStringLiteral(
"MAX_ANGLE" ) ).value<
QgsProperty >();
137 int iterations = mIterations;
138 if ( mDynamicIterations )
139 iterations = mIterationsProperty.valueAsInt( context.
expressionContext(), iterations );
141 double offset = mOffset;
142 if ( mDynamicOffset )
145 double maxAngle = mMaxAngle;
146 if ( mDynamicMaxAngle )
150 if ( outputGeometry.
isNull() )
152 feedback->
reportError( QObject::tr(
"Error smoothing geometry %1" ).arg( feature.
id() ) );