Skip to content

Commit 33ea700

Browse files
author
cfarmer
committed
some quick fixes to voronoi and delaunay tools
git-svn-id: http://svn.osgeo.org/qgis/trunk@14758 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 40fe49d commit 33ea700

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

python/plugins/fTools/tools/doGeometry.py

+11-3
Original file line numberDiff line numberDiff line change
@@ -463,12 +463,16 @@ def delaunay_triangulation( self ):
463463
inFeat = QgsFeature()
464464
c = voronoi.Context()
465465
pts = []
466+
ptDict = {}
467+
ptNdx = -1
466468
while vprovider.nextFeature(inFeat):
467469
geom = QgsGeometry(inFeat.geometry())
468470
point = geom.asPoint()
469471
x = point.x()
470472
y = point.y()
471473
pts.append((x, y))
474+
ptNdx +=1
475+
ptDict[ptNdx] = inFeat.id()
472476
if len(pts) < 3:
473477
return False
474478
uniqueSet = Set(item for item in pts)
@@ -488,7 +492,7 @@ def delaunay_triangulation( self ):
488492
polygon = []
489493
step = 0
490494
for index in indicies:
491-
vprovider.featureAtId( ids[index], inFeat, True, allAttrs )
495+
vprovider.featureAtId(ptDict[ids[index]], inFeat, True, allAttrs)
492496
geom = QgsGeometry(inFeat.geometry())
493497
point = QgsPoint(geom.asPoint())
494498
polygon.append(point)
@@ -517,26 +521,30 @@ def voronoi_polygons( self ):
517521
width = extent.width()
518522
c = voronoi.Context()
519523
pts = []
524+
ptDict = {}
525+
ptNdx = -1
520526
while vprovider.nextFeature(inFeat):
521527
geom = QgsGeometry(inFeat.geometry())
522528
point = geom.asPoint()
523529
x = point.x()-extent.xMinimum()
524530
y = point.y()-extent.yMinimum()
525531
pts.append((x, y))
532+
ptNdx +=1
533+
ptDict[ptNdx] = inFeat.id()
526534
self.vlayer = None
527535
if len(pts) < 3:
528536
return False
529537
uniqueSet = Set(item for item in pts)
530538
ids = [pts.index(item) for item in uniqueSet]
531-
sl = voronoi.SiteList([voronoi.Site(*i, sitenum=j) for j, i in enumerate(uniqueSet)])
539+
sl = voronoi.SiteList([voronoi.Site(i[0], i[1], sitenum=j) for j, i in enumerate(uniqueSet)])
532540
voronoi.voronoi(sl, c)
533541
inFeat = QgsFeature()
534542
nFeat = len(c.polygons)
535543
nElement = 0
536544
self.emit( SIGNAL( "runStatus(PyQt_PyObject)" ), 0 )
537545
self.emit( SIGNAL( "runRange(PyQt_PyObject)" ), ( 0, nFeat ) )
538546
for site, edges in c.polygons.iteritems():
539-
vprovider.featureAtId(ids[site], inFeat, True, allAttrs)
547+
vprovider.featureAtId(ptDict[ids[site]], inFeat, True, allAttrs)
540548
lines = self.clip_voronoi(edges, c, width, height, extent, extraX, extraY)
541549
geom = QgsGeometry.fromMultiPoint(lines)
542550
geom = QgsGeometry(geom.convexHull())

0 commit comments

Comments
 (0)