Skip to content

Commit

Permalink
some quick fixes to voronoi and delaunay tools
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@14758 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
cfarmer committed Nov 24, 2010
1 parent 5084fc4 commit e7ed5ca
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions python/plugins/fTools/tools/doGeometry.py
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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())
Expand Down

0 comments on commit e7ed5ca

Please sign in to comment.