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" ),
QgsProcessingParameterNumber::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" ), QVariant::LongLong ) );
86 fields.
append(
QgsField( QStringLiteral(
"POINTB" ), QVariant::LongLong ) );
87 fields.
append(
QgsField( QStringLiteral(
"POINTC" ), QVariant::LongLong ) );
91 fields.
append(
QgsField( QStringLiteral(
"id" ), QVariant::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 );
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, FieldOrigin origin=OriginProvider, int originIndex=-1)
Appends a field. The field must have unique name, otherwise it is rejected (returns false)
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 addPart(const QVector< QgsPointXY > &points, Qgis::GeometryType geomType=Qgis::GeometryType::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.
@ FlagSkipGeometryValidityChecks
Invalid geometry checks should always be skipped. This flag can be useful for algorithms which always...
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.
@ Double
Double/float values.
@ TypeVectorPolygon
Vector polygon layers.
@ TypeVectorPoint
Vector point layers.
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.