25QString QgsVoronoiPolygonsAlgorithm::name()
 const 
   27  return QStringLiteral( 
"voronoipolygons" );
 
   30QString QgsVoronoiPolygonsAlgorithm::displayName()
 const 
   32  return QObject::tr( 
"Voronoi polygons" );
 
   35QStringList QgsVoronoiPolygonsAlgorithm::tags()
 const 
   37  return QObject::tr( 
"voronoi,polygons,tessellation,diagram" ).split( 
',' );
 
   40QString QgsVoronoiPolygonsAlgorithm::group()
 const 
   42  return QObject::tr( 
"Vector geometry" );
 
   45QString QgsVoronoiPolygonsAlgorithm::groupId()
 const 
   47  return QStringLiteral( 
"vectorgeometry" );
 
   50QString QgsVoronoiPolygonsAlgorithm::shortHelpString()
 const 
   52  return QObject::tr( 
"This algorithm generates a polygon layer containing the Voronoi diagram corresponding to input points." );
 
   55QString QgsVoronoiPolygonsAlgorithm::shortDescription()
 const 
   57  return QObject::tr( 
"Generates a polygon layer containing the Voronoi diagram corresponding to input points." );
 
   60QgsVoronoiPolygonsAlgorithm *QgsVoronoiPolygonsAlgorithm::createInstance()
 const 
   62  return new QgsVoronoiPolygonsAlgorithm();
 
   65void QgsVoronoiPolygonsAlgorithm::initAlgorithm( 
const QVariantMap & )
 
   70  addParameter( 
new QgsProcessingParameterBoolean( QStringLiteral( 
"COPY_ATTRIBUTES" ), QObject::tr( 
"Copy attributes from input features" ), 
true ) );
 
   78  mSource.reset( parameterAsSource( parameters, QStringLiteral( 
"INPUT" ), context ) );
 
   82  if ( mSource->featureCount() < 3 )
 
   85  mBuffer = parameterAsDouble( parameters, QStringLiteral( 
"BUFFER" ), context );
 
   86  mTolerance = parameterAsDouble( parameters, QStringLiteral( 
"TOLERANCE" ), context );
 
   87  mCopyAttributes = parameterAsBool( parameters, QStringLiteral( 
"COPY_ATTRIBUTES" ), context );
 
   95  if ( mCopyAttributes )
 
   97    dest = voronoiWithAttributes( parameters, context, feedback );
 
  101    dest = voronoiWithoutAttributes( parameters, context, feedback );
 
  105  outputs.insert( QStringLiteral( 
"OUTPUT" ), dest );
 
  111  const QgsFields fields = mSource->fields();
 
  114  std::unique_ptr<QgsFeatureSink> sink( parameterAsSink( parameters, QStringLiteral( 
"OUTPUT" ), context, dest, fields, 
Qgis::WkbType::Polygon, mSource->sourceCrs() ) );
 
  122  QHash<QgsFeatureId, QgsAttributes> attributeCache;
 
  125  const double step = mSource->featureCount() > 0 ? 50.0 / mSource->featureCount() : 1;
 
  140      const QgsMultiPoint mp( *qgsgeometry_cast< const QgsMultiPoint * >( geom ) );
 
  141      for ( 
auto pit = mp.const_parts_begin(); pit != mp.const_parts_end(); ++pit )
 
  156  double delta = extent.
width() * mBuffer / 100.0;
 
  157  extent.setXMinimum( extent.xMinimum() - delta );
 
  158  extent.setXMaximum( extent.xMaximum() + delta );
 
  159  delta = extent.height() * mBuffer / 100.0;
 
  160  extent.setYMinimum( extent.yMinimum() - delta );
 
  161  extent.setYMaximum( extent.yMaximum() + delta );
 
  166  if ( !voronoiDiagram.
isEmpty() )
 
  168    std::unique_ptr<QgsGeometryEngine> engine;
 
  172    for ( 
const QgsGeometry &collectionPart : collection )
 
  181      QgsGeometry voronoiClippedToExtent = 
QgsGeometry( extentEngine->intersection( collectionPart.constGet() ) );
 
  183      if ( !voronoiClippedToExtent.
isEmpty() )
 
  186        const QList<QgsFeatureId> intersected = index.intersects( collectionPart.boundingBox() );
 
  188        engine->prepareGeometry();
 
  191          if ( engine->intersects( index.geometry( 
id ).constGet() ) )
 
  213  fields.
append( 
QgsField( QStringLiteral( 
"id" ), QMetaType::Type::LongLong ) );
 
  216  std::unique_ptr<QgsFeatureSink> sink( parameterAsSink( parameters, QStringLiteral( 
"OUTPUT" ), context, dest, fields, 
Qgis::WkbType::Polygon, mSource->sourceCrs() ) );
 
  220  auto points = std::make_unique<QgsMultiPoint>();
 
  223  const double step = mSource->featureCount() > 0 ? 50.0 / mSource->featureCount() : 1;
 
  241      const QgsMultiPoint mp( *qgsgeometry_cast<const QgsMultiPoint *>( geom ) );
 
  242      for ( 
auto pit = mp.const_parts_begin(); pit != mp.const_parts_end(); ++pit )
 
  244        points->addGeometry( qgsgeometry_cast<const QgsPoint *>( *pit )->clone() );
 
  249      points->addGeometry( qgsgeometry_cast<const QgsPoint *>( geom )->clone() );
 
  254  double delta = extent.
width() * mBuffer / 100.0;
 
  257  delta = extent.
height() * mBuffer / 100.0;
 
  265  if ( !voronoiDiagram.
isEmpty() )
 
  267    std::unique_ptr<QgsGeometryEngine> engine;
 
  270    for ( 
int i = 0; i < collection.length(); i++ )
 
@ VectorPoint
Vector point layers.
 
@ VectorPolygon
Vector polygon layers.
 
@ SkipGeometryValidityChecks
Invalid geometry checks should always be skipped. This flag can be useful for algorithms which always...
 
@ Double
Double/float values.
 
Abstract base class for all geometries.
 
virtual const QgsAbstractGeometry * simplifiedTypeRef() const
Returns a reference to the simplest lossless representation of this geometry, e.g.
 
Qgis::WkbType wkbType() const
Returns the WKB type of the geometry.
 
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.
 
Wraps a request for features to a vector layer (or directly its vector data provider).
 
@ 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...
 
void setAttributes(const QgsAttributes &attrs)
Sets the feature's attributes.
 
void setFields(const QgsFields &fields, bool initAttributes=false)
Assigns a field map with the feature to allow attribute access by attribute name.
 
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.
 
Encapsulate a field in an attribute table or data source.
 
Container of fields for a vector layer.
 
bool append(const QgsField &field, Qgis::FieldOrigin origin=Qgis::FieldOrigin::Provider, int originIndex=-1)
Appends a field.
 
A geometry is the spatial representation of a feature.
 
static QgsGeometry fromRect(const QgsRectangle &rect)
Creates a new geometry from a QgsRectangle.
 
QVector< QgsGeometry > asGeometryCollection() const
Returns contents of the geometry as a list of geometries.
 
const QgsAbstractGeometry * constGet() const
Returns a non-modifiable (const) reference to the underlying abstract geometry primitive.
 
QgsGeometry voronoiDiagram(const QgsGeometry &extent=QgsGeometry(), double tolerance=0.0, bool edgesOnly=false) const
Creates a Voronoi diagram for the nodes contained within the geometry.
 
bool isEmpty() const
Returns true if the geometry is empty (eg a linestring with no vertices, or a collection with no geom...
 
bool convertGeometryCollectionToSubclass(Qgis::GeometryType geomType)
Converts geometry collection to a the desired geometry type subclass (multi-point,...
 
Qgis::GeometryOperationResult addPartV2(const QVector< QgsPointXY > &points, Qgis::WkbType wkbType=Qgis::WkbType::Unknown)
Adds a new part to a the geometry.
 
static QgsGeometryEngine * createGeometryEngine(const QgsAbstractGeometry *geometry, double precision=0.0, Qgis::GeosCreationFlags flags=Qgis::GeosCreationFlag::SkipEmptyInteriorRings)
Creates and returns a new geometry engine representing the specified geometry using precision on a gr...
 
Multi point geometry collection.
 
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.
 
A boolean parameter for processing algorithms.
 
A feature sink output for processing algorithms.
 
An input feature source (such as vector layers) parameter for processing algorithms.
 
A numeric parameter for processing algorithms.
 
A rectangle specified with double values.
 
void setYMinimum(double y)
Set the minimum y value.
 
void setXMinimum(double x)
Set the minimum x value.
 
void setYMaximum(double y)
Set the maximum y value.
 
void setXMaximum(double x)
Set the maximum x value.
 
A spatial index for QgsFeature objects.
 
@ FlagStoreFeatureGeometries
Indicates that the spatial index should also store feature geometries. This requires more memory,...
 
static Q_INVOKABLE bool isMultiType(Qgis::WkbType type)
Returns true if the WKB type is a multi type.
 
qint64 QgsFeatureId
64 bit feature ids negative numbers are used for uncommitted/newly added features