1
|
|
2
|
|
3
|
from qgis.core import (QgsProcessing, QgsProcessingAlgorithm, QgsProcessingParameterFeatureSource, QgsGeometry, QgsMultiPoint)
|
4
|
|
5
|
class TestTriangulation(QgsProcessingAlgorithm):
|
6
|
POINTS = 'POINTS'
|
7
|
|
8
|
|
9
|
def createInstance(self):
|
10
|
return TestTriangulation()
|
11
|
|
12
|
def name(self):
|
13
|
return 'testtriangulation'
|
14
|
|
15
|
def displayName(self):
|
16
|
return 'Test Triangulation'
|
17
|
|
18
|
def flags(self):
|
19
|
return QgsProcessingAlgorithm.FlagNoThreading
|
20
|
|
21
|
def group(self):
|
22
|
return 'Test'
|
23
|
|
24
|
def groupId(self):
|
25
|
return 'test'
|
26
|
|
27
|
def shortHelpString(self):
|
28
|
return ''
|
29
|
|
30
|
def initAlgorithm(self, config = None):
|
31
|
self.addParameter(QgsProcessingParameterFeatureSource(self.POINTS, 'Points', [QgsProcessing.TypeVectorPoint]))
|
32
|
|
33
|
|
34
|
def processAlgorithm(self, parameters, context, feedback):
|
35
|
pointLayer = self.parameterAsSource(parameters, self.POINTS, context)
|
36
|
multiPoint = QgsMultiPoint()
|
37
|
for pointFeature in pointLayer.getFeatures():
|
38
|
multiPoint.addGeometry(pointFeature.geometry().vertexAt(0))
|
39
|
multiPointGeometry = QgsGeometry(multiPoint)
|
40
|
triangulation = multiPointGeometry.delaunayTriangulation(1e-3)
|
41
|
multiTriangle = triangulation.get()
|
42
|
|
43
|
for i in range(multiTriangle.numGeometries()):
|
44
|
triangle = multiTriangle.geometryN(i)
|
45
|
triangleGeometry = QgsGeometry(triangle)
|
46
|
|
47
|
|
48
|
|
49
|
return {}
|