26QString QgsCoverageSimplifyAlgorithm::name()
 const 
   28  return QStringLiteral( 
"coveragesimplify" );
 
   31QString QgsCoverageSimplifyAlgorithm::displayName()
 const 
   33  return QObject::tr( 
"Simplify coverage" );
 
   36QStringList QgsCoverageSimplifyAlgorithm::tags()
 const 
   38  return QObject::tr( 
"topological,boundary" ).split( 
',' );
 
   41QString QgsCoverageSimplifyAlgorithm::group()
 const 
   43  return QObject::tr( 
"Vector coverage" );
 
   46QString QgsCoverageSimplifyAlgorithm::groupId()
 const 
   48  return QStringLiteral( 
"vectorcoverage" );
 
   51void QgsCoverageSimplifyAlgorithm::initAlgorithm( 
const QVariantMap & )
 
   54  addParameter( 
new QgsProcessingParameterDistance( QStringLiteral( 
"TOLERANCE" ), QObject::tr( 
"Tolerance" ), 1.0, QStringLiteral( 
"INPUT" ), 
false, 0, 10000000.0 ) );
 
   55  auto boundaryParameter = std::make_unique<QgsProcessingParameterBoolean>( QStringLiteral( 
"PRESERVE_BOUNDARY" ), QObject::tr( 
"Preserve boundary" ), 
false );
 
   56  boundaryParameter->setHelp( QObject::tr( 
"When enabled the outside edges of the coverage will be preserved without simplification." ) );
 
   57  addParameter( boundaryParameter.release() );
 
   62QString QgsCoverageSimplifyAlgorithm::shortDescription()
 const 
   64  return QObject::tr( 
"Simplifies a coverage of polygon features while retaining valid coverage." );
 
   67QString QgsCoverageSimplifyAlgorithm::shortHelpString()
 const 
   69  return QObject::tr( 
"This algorithm operates on a coverage (represented as a set of polygon features " 
   70                      "with exactly matching edge geometry) to apply a Visvalingam–Whyatt " 
   71                      "simplification to the edges, reducing complexity in proportion with " 
   72                      "the provided tolerance, while retaining a valid coverage (i.e. no edges " 
   73                      "will cross or touch after the simplification).\n\n" 
   74                      "Geometries will never be removed, but they may be simplified down to just " 
   75                      "a triangle. Also, some geometries (such as polygons which have too " 
   76                      "few non-repeated points) will be returned unchanged.\n\n" 
   77                      "If the input dataset is not a valid coverage due to overlaps, " 
   78                      "it will still be simplified, but invalid topology such as crossing " 
   79                      "edges will still be invalid." );
 
   82QgsCoverageSimplifyAlgorithm *QgsCoverageSimplifyAlgorithm::createInstance()
 const 
   84  return new QgsCoverageSimplifyAlgorithm();
 
   89  std::unique_ptr<QgsProcessingFeatureSource> source( parameterAsSource( parameters, QStringLiteral( 
"INPUT" ), context ) );
 
   93  const bool preserveBoundary = parameterAsBoolean( parameters, QStringLiteral( 
"PRESERVE_BOUNDARY" ), context );
 
   94  const double tolerance = parameterAsDouble( parameters, QStringLiteral( 
"TOLERANCE" ), context );
 
   97  std::unique_ptr<QgsFeatureSink> sink( parameterAsSink( parameters, QStringLiteral( 
"OUTPUT" ), context, sinkId, source->fields(), source->wkbType(), source->sourceCrs() ) );
 
  102  QVector<QgsFeature> featuresWithGeom;
 
  103  QVector<QgsFeature> featuresWithoutGeom;
 
  106  const long count = source->featureCount();
 
  109    featuresWithGeom.
reserve( count );
 
  113  const double step = count > 0 ? 100.0 / count : 1;
 
  116  feedback->
pushInfo( QObject::tr( 
"Collecting features" ) );
 
  129      featuresWithGeom.append( inFeature );
 
  134      featuresWithoutGeom.append( inFeature );
 
  144  switch ( source->invalidGeometryCheck() )
 
  160  feedback->
pushInfo( QObject::tr( 
"Simplifying coverage" ) );
 
  162  std::unique_ptr<QgsAbstractGeometry> simplified;
 
  165    simplified = 
geos.simplifyCoverageVW( tolerance, preserveBoundary, &error );
 
  174    if ( !error.isEmpty() )
 
  182  feedback->
pushInfo( QObject::tr( 
"Storing features" ) );
 
  183  long long featureIndex = 0;
 
  184  for ( 
auto partsIt = simplified->const_parts_begin(); partsIt != simplified->const_parts_end(); ++partsIt )
 
  186    QgsFeature outFeature = featuresWithGeom.value( featureIndex );
 
  192    feedback->
setProgress( featureIndex * step * 0.2 + 80 );
 
  195  for ( 
const QgsFeature &feature : featuresWithoutGeom )
 
  205  outputs.insert( QStringLiteral( 
"OUTPUT" ), sinkId );
 
@ VectorPolygon
Vector polygon layers.
 
@ Valid
Coverage is valid.
 
@ NoCheck
No invalid geometry checking.
 
@ AbortOnInvalid
Close iterator on encountering any features with invalid geometry. This requires a slow geometry vali...
 
@ SkipInvalid
Skip any features with invalid geometry. This requires a slow geometry validity check for every featu...
 
virtual QgsAbstractGeometry * clone() const =0
Clones the geometry by performing a deep copy.
 
Wrapper for iterator of features from vector data provider or vector layer.
 
bool nextFeature(QgsFeature &f)
Fetch next feature and stores in f, returns true on success.
 
@ FastInsert
Use faster inserts, at the cost of updating the passed features to reflect changes made at the provid...
 
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.
 
bool isCanceled() const
Tells whether the operation has been canceled already.
 
void setProgress(double progress)
Sets the current progress for the feedback object.
 
void reserve(int size)
Attempts to allocate memory for at least size geometries.
 
virtual bool addGeometry(QgsAbstractGeometry *g)
Adds a geometry and takes ownership. Returns true in case of success.
 
A geometry is the spatial representation of a feature.
 
const QgsAbstractGeometry * constGet() const
Returns a non-modifiable (const) reference to the underlying abstract geometry primitive.
 
Does vector analysis using the GEOS library and handles import, export, and exception handling.
 
Custom exception class which is raised when an operation is not supported.
 
Contains information about the context in which a processing algorithm is executed.
 
Custom exception class for processing related exceptions.
 
Base class for providing feedback from a processing algorithm.
 
virtual void pushInfo(const QString &info)
Pushes a general informational message from the algorithm.
 
A double numeric parameter for distance values.
 
A feature sink output for processing algorithms.
 
An input feature source (such as vector layers) parameter for processing algorithms.
 
Contains geos related utilities and functions.