25QString QgsDelaunayTriangulationAlgorithm::name()
const
27 return QStringLiteral(
"delaunaytriangulation" );
30QString QgsDelaunayTriangulationAlgorithm::displayName()
const
32 return QObject::tr(
"Delaunay triangulation" );
35QStringList QgsDelaunayTriangulationAlgorithm::tags()
const
37 return QObject::tr(
"delaunay,triangulation,polygons,voronoi" ).split(
',' );
40QString QgsDelaunayTriangulationAlgorithm::group()
const
42 return QObject::tr(
"Vector geometry" );
45QString QgsDelaunayTriangulationAlgorithm::groupId()
const
47 return QStringLiteral(
"vectorgeometry" );
50QString QgsDelaunayTriangulationAlgorithm::shortHelpString()
const
52 return QObject::tr(
"Creates a polygon layer with the Delaunay triangulation corresponding to a points layer." );
55QgsDelaunayTriangulationAlgorithm *QgsDelaunayTriangulationAlgorithm::createInstance()
const
57 return new QgsDelaunayTriangulationAlgorithm();
60void QgsDelaunayTriangulationAlgorithm::initAlgorithm(
const QVariantMap & )
63 std::unique_ptr<QgsProcessingParameterNumber> toleranceParam = std::make_unique<QgsProcessingParameterNumber>( QStringLiteral(
"TOLERANCE" ), QObject::tr(
"Tolerance" ),
Qgis::ProcessingNumberParameterType::Double, 0,
true, 0 );
64 toleranceParam->setHelp( QObject::tr(
"Specifies an optional snapping tolerance which can be used to improve the robustness of the triangulation" ) );
65 addParameter( toleranceParam.release() );
72 std::unique_ptr< QgsProcessingFeatureSource > source( parameterAsSource( parameters, QStringLiteral(
"INPUT" ), context ) );
76 if ( source->featureCount() < 3 )
79 const double tolerance = parameterAsDouble( parameters, QStringLiteral(
"TOLERANCE" ), context );
80 const bool addAttributes = parameterAsBool( parameters, QStringLiteral(
"ADD_ATTRIBUTES" ), context );
85 fields.
append(
QgsField( QStringLiteral(
"POINTA" ), QMetaType::Type::LongLong ) );
86 fields.
append(
QgsField( QStringLiteral(
"POINTB" ), QMetaType::Type::LongLong ) );
87 fields.
append(
QgsField( QStringLiteral(
"POINTC" ), QMetaType::Type::LongLong ) );
91 fields.
append(
QgsField( QStringLiteral(
"id" ), QMetaType::Type::LongLong ) );
95 std::unique_ptr< QgsFeatureSink > sink( parameterAsSink( parameters, QStringLiteral(
"OUTPUT" ), context, dest, fields,
Qgis::WkbType::Polygon, source->sourceCrs() ) );
104 const double step = source->featureCount() > 0 ? 50.0 / source->featureCount() : 1;
120 const QgsMultiPoint mp( *qgsgeometry_cast< const QgsMultiPoint * >( geom ) );
121 for (
auto pit = mp.const_parts_begin(); pit != mp.const_parts_end(); ++pit )
136 if ( !triangulation.isEmpty() )
139 for (
int i = 0; i < collection.length(); i++ )
150 const QList< QgsFeatureId > nearest = index.nearestNeighbor( collection[i], 3 );
152 for (
int j = 0; j < 3; j++ )
154 attrs << nearest.at( j );
170 outputs.insert( QStringLiteral(
"OUTPUT" ), dest );
@ 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.
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.
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.
Qgis::GeometryOperationResult addPartV2(const QVector< QgsPointXY > &points, Qgis::WkbType wkbType=Qgis::WkbType::Unknown)
Adds a new part to a the geometry.
QgsGeometry delaunayTriangulation(double tolerance=0.0, bool edgesOnly=false) const
Returns the Delaunay triangulation for the vertices of the geometry.
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 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.