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
65 "This algorithm simplifies the geometries in a line or polygon layer. It creates a new layer "
66 "with the same features as the ones in the input layer, but with geometries containing a lower number of vertices.\n\n"
67 "The algorithm gives a choice of simplification methods, including distance based "
68 "(the \"Douglas-Peucker\" algorithm), area based (\"Visvalingam\" algorithm) and snapping geometries to a grid."
72QString QgsSimplifyAlgorithm::shortDescription()
const
74 return QObject::tr(
"Simplifies the geometries in a line or polygon layer by removing a number of vertices." );
77QgsSimplifyAlgorithm *QgsSimplifyAlgorithm::createInstance()
const
79 return new QgsSimplifyAlgorithm();
82QList<int> QgsSimplifyAlgorithm::inputLayerTypes()
const
87void QgsSimplifyAlgorithm::initParameters(
const QVariantMap & )
90 methods << QObject::tr(
"Distance (Douglas-Peucker)" ) << QObject::tr(
"Snap to grid" ) << QObject::tr(
"Area (Visvalingam)" );
93 auto tolerance = std::make_unique<QgsProcessingParameterDistance>( u
"TOLERANCE"_s, QObject::tr(
"Tolerance" ), 1.0, u
"INPUT"_s,
false, 0, 10000000.0 );
94 tolerance->setIsDynamic(
true );
96 tolerance->setDynamicLayerParameterName( u
"INPUT"_s );
97 addParameter( tolerance.release() );
102 mTolerance = parameterAsDouble( parameters, u
"TOLERANCE"_s, context );
104 if ( mDynamicTolerance )
105 mToleranceProperty = parameters.value( u
"TOLERANCE"_s ).value<
QgsProperty>();
123 double tolerance = mTolerance;
124 if ( mDynamicTolerance )
125 tolerance = mToleranceProperty.valueAsDouble( context.
expressionContext(), tolerance );
126 outputGeometry = inputGeometry.
simplify( tolerance );
130 if ( !mDynamicTolerance )
132 outputGeometry = mSimplifier->
simplify( inputGeometry );
136 const double tolerance = mToleranceProperty.valueAsDouble( context.
expressionContext(), mTolerance );
138 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