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(
"Generates a polygon layer containing the Voronoi diagram corresponding to input points." );
55QgsVoronoiPolygonsAlgorithm *QgsVoronoiPolygonsAlgorithm::createInstance()
const
57 return new QgsVoronoiPolygonsAlgorithm();
60void QgsVoronoiPolygonsAlgorithm::initAlgorithm(
const QVariantMap & )
65 addParameter(
new QgsProcessingParameterBoolean( QStringLiteral(
"COPY_ATTRIBUTES" ), QObject::tr(
"Copy attributes from input features" ),
true ) );
73 mSource.reset( parameterAsSource( parameters, QStringLiteral(
"INPUT" ), context ) );
77 if ( mSource->featureCount() < 3 )
80 mBuffer = parameterAsDouble( parameters, QStringLiteral(
"BUFFER" ), context );
81 mTolerance = parameterAsDouble( parameters, QStringLiteral(
"TOLERANCE" ), context );
82 mCopyAttributes = parameterAsBool( parameters, QStringLiteral(
"COPY_ATTRIBUTES" ), context );
90 if ( mCopyAttributes )
92 dest = voronoiWithAttributes( parameters, context, feedback );
96 dest = voronoiWithoutAttributes( parameters, context, feedback );
100 outputs.insert( QStringLiteral(
"OUTPUT" ), dest );
106 const QgsFields fields = mSource->fields();
109 std::unique_ptr< QgsFeatureSink > sink( parameterAsSink( parameters, QStringLiteral(
"OUTPUT" ), context, dest, fields,
Qgis::WkbType::Polygon, mSource->sourceCrs() ) );
117 QHash< QgsFeatureId, QgsAttributes > attributeCache;
120 const double step = mSource->featureCount() > 0 ? 50.0 / mSource->featureCount() : 1;
136 const QgsMultiPoint mp( *qgsgeometry_cast< const QgsMultiPoint * >( geom ) );
137 for (
auto pit = mp.const_parts_begin(); pit != mp.const_parts_end(); ++pit )
153 double delta = extent.
width() * mBuffer / 100.0;
154 extent.setXMinimum( extent.xMinimum() - delta );
155 extent.setXMaximum( extent.xMaximum() + delta );
156 delta = extent.height() * mBuffer / 100.0;
157 extent.setYMinimum( extent.yMinimum() - delta );
158 extent.setYMaximum( extent.yMaximum() + delta );
163 if ( !voronoiDiagram.
isEmpty() )
165 std::unique_ptr< QgsGeometryEngine > engine;
168 for (
int i = 0; i < collection.length(); i++ )
177 const QList< QgsFeatureId > intersected = index.intersects( collection[i].boundingBox() );
179 engine->prepareGeometry();
182 if ( engine->intersects( index.geometry(
id ).constGet() ) )
200 fields.
append(
QgsField( QStringLiteral(
"id" ), QMetaType::Type::LongLong ) );
203 std::unique_ptr< QgsFeatureSink > sink( parameterAsSink( parameters, QStringLiteral(
"OUTPUT" ), context, dest, fields,
Qgis::WkbType::Polygon, mSource->sourceCrs() ) );
207 std::unique_ptr< QgsMultiPoint > points = std::make_unique< QgsMultiPoint >();
210 const double step = mSource->featureCount() > 0 ? 50.0 / mSource->featureCount() : 1;
228 const QgsMultiPoint mp( *qgsgeometry_cast< const QgsMultiPoint * >( geom ) );
229 for (
auto pit = mp.const_parts_begin(); pit != mp.const_parts_end(); ++pit )
231 points->addGeometry( qgsgeometry_cast< QgsPoint * >( *pit )->clone() );
236 points->addGeometry( qgsgeometry_cast< QgsPoint * >( geom )->clone() );
241 double delta = extent.
width() * mBuffer / 100.0;
244 delta = extent.
height() * mBuffer / 100.0;
252 if ( !voronoiDiagram.
isEmpty() )
254 std::unique_ptr< QgsGeometryEngine > engine;
257 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.
Qgis::WkbType wkbType() const
Returns the WKB type of the geometry.
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.
This class 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...
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)
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.
double xMinimum() const
Returns the x minimum value (left side of rectangle).
void setYMinimum(double y)
Set the minimum y value.
double yMinimum() const
Returns the y minimum value (bottom side of rectangle).
void setXMinimum(double x)
Set the minimum x value.
double width() const
Returns the width of the rectangle.
double xMaximum() const
Returns the x maximum value (right side of rectangle).
double yMaximum() const
Returns the y maximum value (top side of rectangle).
void setYMaximum(double y)
Set the maximum y value.
void setXMaximum(double x)
Set the maximum x value.
double height() const
Returns the height of the rectangle.
A spatial index for QgsFeature objects.
@ FlagStoreFeatureGeometries
Indicates that the spatial index should also store feature geometries. This requires more memory,...
static 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