TransWikia.com

Incomplete Delaunay triangulation unsing pyqgis3

Geographic Information Systems Asked on January 30, 2021

I’m writing a small Qgis3 python plugin to convert polygon shapefiles to input files for a scientific model.
I therefore need to split up the polygon geometries to more simple geometries with up to 4 vertices.
The most simple way that crossed my mind was making use of the generic function delaunayTriangulation, that I suppose, would split my geometries into triangles. I did the following (simplified excerpt, replaced polygon by example-WKT so you can try):

# get current geometry from buildings layer
# polygonGeometry = buildingGeometries[b]  # get a building geometry, all valid polygons, tested before
polygonGeometry = QgsGeometry.fromWkt('PolygonZ ((3413873.66000000014901161 5318284.88999999966472387 286.15166666666664241, 3413878.89999999990686774 5318283.04999999981373549 286.15166666666664241, 3413860.56000000005587935 5318227.38999999966472387 286.15166666666664241, 3413806.66000000014901161 5318245.30999999959021807 286.15166666666664241, 3413805.93000000016763806 5318243.12000000011175871 286.15166666666664241, 3413805.22000000020489097 5318243.30999999959021807 286.15166666666664241, 3413790.99000000022351742 5318200.08999999985098839 286.15166666666664241, 3413774.7099999999627471 5318205.36000000033527613 286.15166666666664241, 3413793.41999999992549419 5318261.62000000011175871 286.15166666666664241, 3413794 5318261.44000000040978193 286.15166666666664241, 3413808.87999999988824129 5318306.34999999962747097 286.15166666666664241, 3413814.14000000013038516 5318304.58999999985098839 286.15166666666664241, 3413811.62999999988824129 5318296.96999999973922968 286.15166666666664241, 3413822.52999999979510903 5318293.36000000033527613 286.15166666666664241, 3413812 5318261.4599999999627471 286.15166666666664241, 3413849.68999999994412065 5318249.07000000029802322 286.15166666666664241, 3413860.33999999985098839 5318280.83999999985098839 286.15166666666664241, 3413871.14000000013038516 5318277.26999999955296516 286.15166666666664241, 3413873.66000000014901161 5318284.88999999966472387 286.15166666666664241))')

# do Delaunay triangulation to split the polygons in a fast and simple way
triangles = polygonGeometry.delaunayTriangulation(0.01, False)

# convert the result to a GeometryCollection to facilitate extraction of individual items
triangles = triangles.asGeometryCollection()

# iterate over all individual triangles 't' in the geometryCollection 'triangles'
for t in triangles:
   # all t are Polygons with 4 points while 1st and last point are the same
   
   # test if polygon is outside original polygon (might happen for multi polygons)
   if (polygonGeometry.contains(t)): # if the original polygon contains t
     
     # write trinagles to output layer

However, the ouput I get (violet triangles) sems to be lacking some triangles (orange polygones are the source layer).

DelaunayTriangulation fails at orange areas

Am I missing something?

Or could you think of some hack to fix the issue?

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP