Skip to content
Permalink
Browse files

some quick fixes to voronoi and delaunay tools

git-svn-id: http://svn.osgeo.org/qgis/trunk@14758 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
cfarmer
cfarmer committed Nov 24, 2010
1 parent 40fe49d commit 33ea700da4a939292b6d73dc15a606a800b947b6
Showing with 11 additions and 3 deletions.
  1. +11 −3 python/plugins/fTools/tools/doGeometry.py
@@ -463,12 +463,16 @@ def delaunay_triangulation( self ):
inFeat = QgsFeature()
c = voronoi.Context()
pts = []
ptDict = {}
ptNdx = -1
while vprovider.nextFeature(inFeat):
geom = QgsGeometry(inFeat.geometry())
point = geom.asPoint()
x = point.x()
y = point.y()
pts.append((x, y))
ptNdx +=1
ptDict[ptNdx] = inFeat.id()
if len(pts) < 3:
return False
uniqueSet = Set(item for item in pts)
@@ -488,7 +492,7 @@ def delaunay_triangulation( self ):
polygon = []
step = 0
for index in indicies:
vprovider.featureAtId( ids[index], inFeat, True, allAttrs )
vprovider.featureAtId(ptDict[ids[index]], inFeat, True, allAttrs)
geom = QgsGeometry(inFeat.geometry())
point = QgsPoint(geom.asPoint())
polygon.append(point)
@@ -517,26 +521,30 @@ def voronoi_polygons( self ):
width = extent.width()
c = voronoi.Context()
pts = []
ptDict = {}
ptNdx = -1
while vprovider.nextFeature(inFeat):
geom = QgsGeometry(inFeat.geometry())
point = geom.asPoint()
x = point.x()-extent.xMinimum()
y = point.y()-extent.yMinimum()
pts.append((x, y))
ptNdx +=1
ptDict[ptNdx] = inFeat.id()
self.vlayer = None
if len(pts) < 3:
return False
uniqueSet = Set(item for item in pts)
ids = [pts.index(item) for item in uniqueSet]
sl = voronoi.SiteList([voronoi.Site(*i, sitenum=j) for j, i in enumerate(uniqueSet)])
sl = voronoi.SiteList([voronoi.Site(i[0], i[1], sitenum=j) for j, i in enumerate(uniqueSet)])
voronoi.voronoi(sl, c)
inFeat = QgsFeature()
nFeat = len(c.polygons)
nElement = 0
self.emit( SIGNAL( "runStatus(PyQt_PyObject)" ), 0 )
self.emit( SIGNAL( "runRange(PyQt_PyObject)" ), ( 0, nFeat ) )
for site, edges in c.polygons.iteritems():
vprovider.featureAtId(ids[site], inFeat, True, allAttrs)
vprovider.featureAtId(ptDict[ids[site]], inFeat, True, allAttrs)
lines = self.clip_voronoi(edges, c, width, height, extent, extraX, extraY)
geom = QgsGeometry.fromMultiPoint(lines)
geom = QgsGeometry(geom.convexHull())

0 comments on commit 33ea700

Please sign in to comment.
You can’t perform that action at this time.