26using namespace Qt::StringLiterals;
30QgsSimplifyAlgorithm::~QgsSimplifyAlgorithm() =
default;
32QString QgsSimplifyAlgorithm::name()
const
34 return u
"simplifygeometries"_s;
37QString QgsSimplifyAlgorithm::displayName()
const
39 return QObject::tr(
"Simplify" );
42QStringList QgsSimplifyAlgorithm::tags()
const
44 return QObject::tr(
"simplify,generalize,douglas,peucker,visvalingam" ).split(
',' );
47QString QgsSimplifyAlgorithm::group()
const
49 return QObject::tr(
"Vector geometry" );
52QString QgsSimplifyAlgorithm::groupId()
const
54 return u
"vectorgeometry"_s;
57QString QgsSimplifyAlgorithm::outputName()
const
59 return QObject::tr(
"Simplified" );
62QString QgsSimplifyAlgorithm::shortHelpString()
const
64 return QObject::tr(
"This algorithm simplifies the geometries in a line or polygon layer. It creates a new layer "
65 "with the same features as the ones in the input layer, but with geometries containing a lower number of vertices.\n\n"
66 "The algorithm gives a choice of simplification methods, including distance based "
67 "(the \"Douglas-Peucker\" algorithm), area based (\"Visvalingam\" algorithm) and snapping geometries to a grid." );
70QString QgsSimplifyAlgorithm::shortDescription()
const
72 return QObject::tr(
"Simplifies the geometries in a line or polygon layer by removing a number of vertices." );
75QgsSimplifyAlgorithm *QgsSimplifyAlgorithm::createInstance()
const
77 return new QgsSimplifyAlgorithm();
80QList<int> QgsSimplifyAlgorithm::inputLayerTypes()
const
85void QgsSimplifyAlgorithm::initParameters(
const QVariantMap & )
88 methods << QObject::tr(
"Distance (Douglas-Peucker)" )
89 << QObject::tr(
"Snap to grid" )
90 << QObject::tr(
"Area (Visvalingam)" );
94 QObject::tr(
"Simplification method" ),
97 auto tolerance = std::make_unique<QgsProcessingParameterDistance>( u
"TOLERANCE"_s, QObject::tr(
"Tolerance" ), 1.0, u
"INPUT"_s,
false, 0, 10000000.0 );
98 tolerance->setIsDynamic(
true );
100 tolerance->setDynamicLayerParameterName( u
"INPUT"_s );
101 addParameter( tolerance.release() );
106 mTolerance = parameterAsDouble( parameters, u
"TOLERANCE"_s, context );
108 if ( mDynamicTolerance )
109 mToleranceProperty = parameters.value( u
"TOLERANCE"_s ).value<
QgsProperty>();
127 double tolerance = mTolerance;
128 if ( mDynamicTolerance )
129 tolerance = mToleranceProperty.valueAsDouble( context.
expressionContext(), tolerance );
130 outputGeometry = inputGeometry.
simplify( tolerance );
134 if ( !mDynamicTolerance )
136 outputGeometry = mSimplifier->
simplify( inputGeometry );
140 const double tolerance = mToleranceProperty.valueAsDouble( context.
expressionContext(), mTolerance );
142 outputGeometry = simplifier.
simplify( inputGeometry );
@ VectorPolygon
Vector polygon layers.
@ VectorLine
Vector line layers.
VectorSimplificationAlgorithm
Simplification algorithms for vector features.
@ Distance
The simplification uses the distance between points to remove duplicate points.
@ 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.
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 simplify(double tolerance) const
Returns a simplified version of this geometry using a specified tolerance value.
Implementation of a geometry simplifier using the "MapToPixel" algorithm.
@ SimplifyGeometry
The geometries can be simplified using the current map2pixel context state.
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.
An enum based parameter for processing algorithms, allowing for selection from predefined 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...
Definition for a property.
@ DoublePositive
Positive double value (including 0).
A store for object properties.
QList< QgsFeature > QgsFeatureList