26QString QgsVoronoiPolygonsAlgorithm::name()
const
28 return QStringLiteral(
"voronoipolygons" );
31QString QgsVoronoiPolygonsAlgorithm::displayName()
const
33 return QObject::tr(
"Voronoi polygons" );
36QStringList QgsVoronoiPolygonsAlgorithm::tags()
const
38 return QObject::tr(
"voronoi,polygons,tessellation,diagram" ).split(
',' );
41QString QgsVoronoiPolygonsAlgorithm::group()
const
43 return QObject::tr(
"Vector geometry" );
46QString QgsVoronoiPolygonsAlgorithm::groupId()
const
48 return QStringLiteral(
"vectorgeometry" );
51QString QgsVoronoiPolygonsAlgorithm::shortHelpString()
const
53 return QObject::tr(
"This algorithm generates a polygon layer containing the Voronoi diagram corresponding to input points." );
56QString QgsVoronoiPolygonsAlgorithm::shortDescription()
const
58 return QObject::tr(
"Generates a polygon layer containing the Voronoi diagram corresponding to input points." );
61QgsVoronoiPolygonsAlgorithm *QgsVoronoiPolygonsAlgorithm::createInstance()
const
63 return new QgsVoronoiPolygonsAlgorithm();
66void QgsVoronoiPolygonsAlgorithm::initAlgorithm(
const QVariantMap & )
71 addParameter(
new QgsProcessingParameterBoolean( QStringLiteral(
"COPY_ATTRIBUTES" ), QObject::tr(
"Copy attributes from input features" ),
true ) );
79 mSource.reset( parameterAsSource( parameters, QStringLiteral(
"INPUT" ), context ) );
83 if ( mSource->featureCount() < 3 )
86 mBuffer = parameterAsDouble( parameters, QStringLiteral(
"BUFFER" ), context );
87 mTolerance = parameterAsDouble( parameters, QStringLiteral(
"TOLERANCE" ), context );
88 mCopyAttributes = parameterAsBool( parameters, QStringLiteral(
"COPY_ATTRIBUTES" ), context );
96 if ( mCopyAttributes )
98 dest = voronoiWithAttributes( parameters, context, feedback );
102 dest = voronoiWithoutAttributes( parameters, context, feedback );
106 outputs.insert( QStringLiteral(
"OUTPUT" ), dest );
112 const QgsFields fields = mSource->fields();
115 std::unique_ptr<QgsFeatureSink> sink( parameterAsSink( parameters, QStringLiteral(
"OUTPUT" ), context, dest, fields,
Qgis::WkbType::Polygon, mSource->sourceCrs() ) );
123 QHash<QgsFeatureId, QgsAttributes> attributeCache;
126 const double step = mSource->featureCount() > 0 ? 50.0 / mSource->featureCount() : 1;
142 for (
auto pit = mp.const_parts_begin(); pit != mp.const_parts_end(); ++pit )
157 double delta = extent.
width() * mBuffer / 100.0;
158 extent.setXMinimum( extent.xMinimum() - delta );
159 extent.setXMaximum( extent.xMaximum() + delta );
160 delta = extent.height() * mBuffer / 100.0;
161 extent.setYMinimum( extent.yMinimum() - delta );
162 extent.setYMaximum( extent.yMaximum() + delta );
167 if ( !voronoiDiagram.
isEmpty() )
169 std::unique_ptr<QgsGeometryEngine> engine;
173 for (
const QgsGeometry &collectionPart : collection )
182 QgsGeometry voronoiClippedToExtent =
QgsGeometry( extentEngine->intersection( collectionPart.constGet() ) );
184 if ( !voronoiClippedToExtent.
isEmpty() )
187 const QList<QgsFeatureId> intersected = index.intersects( collectionPart.boundingBox() );
189 engine->prepareGeometry();
192 if ( engine->intersects( index.geometry(
id ).constGet() ) )
214 fields.
append(
QgsField( QStringLiteral(
"id" ), QMetaType::Type::LongLong ) );
217 std::unique_ptr<QgsFeatureSink> sink( parameterAsSink( parameters, QStringLiteral(
"OUTPUT" ), context, dest, fields,
Qgis::WkbType::Polygon, mSource->sourceCrs() ) );
221 auto points = std::make_unique<QgsMultiPoint>();
224 const double step = mSource->featureCount() > 0 ? 50.0 / mSource->featureCount() : 1;
243 for (
auto pit = mp.const_parts_begin(); pit != mp.const_parts_end(); ++pit )
255 double delta = extent.
width() * mBuffer / 100.0;
258 delta = extent.
height() * mBuffer / 100.0;
266 if ( !voronoiDiagram.
isEmpty() )
268 std::unique_ptr<QgsGeometryEngine> engine;
271 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.
T qgsgeometry_cast(QgsAbstractGeometry *geom)
qint64 QgsFeatureId
64 bit feature ids negative numbers are used for uncommitted/newly added features