22 QString QgsSimplifyAlgorithm::name()
const
24 return QStringLiteral(
"simplifygeometries" );
27 QString QgsSimplifyAlgorithm::displayName()
const
29 return QObject::tr(
"Simplify" );
32 QStringList QgsSimplifyAlgorithm::tags()
const
34 return QObject::tr(
"simplify,generalize,douglas,peucker,visvalingam" ).split(
',' );
37 QString QgsSimplifyAlgorithm::group()
const
39 return QObject::tr(
"Vector geometry" );
42 QString QgsSimplifyAlgorithm::groupId()
const
44 return QStringLiteral(
"vectorgeometry" );
47 QString QgsSimplifyAlgorithm::outputName()
const
49 return QObject::tr(
"Simplified" );
52 QString QgsSimplifyAlgorithm::shortHelpString()
const
54 return QObject::tr(
"This algorithm simplifies the geometries in a line or polygon layer. It creates a new layer "
55 "with the same features as the ones in the input layer, but with geometries containing a lower number of vertices.\n\n"
56 "The algorithm gives a choice of simplification methods, including distance based "
57 "(the \"Douglas-Peucker\" algorithm), area based (\"Visvalingam\" algorithm) and snapping geometries to a grid." );
60 QgsSimplifyAlgorithm *QgsSimplifyAlgorithm::createInstance()
const
62 return new QgsSimplifyAlgorithm();
65 QList<int> QgsSimplifyAlgorithm::inputLayerTypes()
const
70 void QgsSimplifyAlgorithm::initParameters(
const QVariantMap & )
73 methods << QObject::tr(
"Distance (Douglas-Peucker)" )
74 << QObject::tr(
"Snap to grid" )
75 << QObject::tr(
"Area (Visvalingam)" );
78 QStringLiteral(
"METHOD" ),
79 QObject::tr(
"Simplification method" ),
80 methods,
false, 0 ) );
81 std::unique_ptr< QgsProcessingParameterDistance > tolerance = std::make_unique< QgsProcessingParameterDistance >( QStringLiteral(
"TOLERANCE" ),
82 QObject::tr(
"Tolerance" ), 1.0, QStringLiteral(
"INPUT" ),
false, 0, 10000000.0 );
83 tolerance->setIsDynamic(
true );
85 tolerance->setDynamicLayerParameterName( QStringLiteral(
"INPUT" ) );
86 addParameter( tolerance.release() );
91 mTolerance = parameterAsDouble( parameters, QStringLiteral(
"TOLERANCE" ), context );
93 if ( mDynamicTolerance )
94 mToleranceProperty = parameters.value( QStringLiteral(
"TOLERANCE" ) ).value<
QgsProperty >();
112 double tolerance = mTolerance;
113 if ( mDynamicTolerance )
114 tolerance = mToleranceProperty.valueAsDouble( context.
expressionContext(), tolerance );
115 outputGeometry = inputGeometry.
simplify( tolerance );
119 if ( !mDynamicTolerance )
121 outputGeometry = mSimplifier->
simplify( inputGeometry );
125 const double tolerance = mToleranceProperty.valueAsDouble( context.
expressionContext(), mTolerance );
127 outputGeometry = simplifier.
simplify( inputGeometry );