Skip to content

Commit

Permalink
Merge pull request #712 from ddanielvaz/fix-8219
Browse files Browse the repository at this point in the history
Fix 8219
  • Loading branch information
NathanW2 committed Jul 11, 2013
2 parents b50a893 + 522aecc commit b45b7d6
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions python/plugins/fTools/tools/doGeoprocessing.py
Expand Up @@ -463,13 +463,26 @@ def convex_hull(self, useField ):
GEOS_EXCEPT = True
FEATURE_EXCEPT = True
vproviderA = self.vlayerA.dataProvider()
writer = QgsVectorFileWriter( self.myName, self.myEncoding, vproviderA.fields(),
# creating fields
idField = QgsField("outID", QVariant.String)
areaField = QgsField("area", QVariant.Double)
perimField = QgsField("perim", QVariant.Double)
# appending fields
outFeatFields = QgsFields()
outFeatFields.append(idField)
outFeatFields.append(areaField)
outFeatFields.append(perimField)
#
writer = QgsVectorFileWriter( self.myName, self.myEncoding, outFeatFields,
QGis.WKBPolygon, vproviderA.crs() )
if writer.hasError():
return GEOS_EXCEPT, FEATURE_EXCEPT, True, writer.errorMessage()

inFeat = QgsFeature()
outFeat = QgsFeature()
# set feature fields
outFeat.setFields(outFeatFields)
#
inGeom = QgsGeometry()
outGeom = QgsGeometry()
nElement = 0
Expand All @@ -487,11 +500,10 @@ def convex_hull(self, useField ):
hull = []
first = True
outID = 0
vproviderA.rewind()
for inFeat in selectionA:
atMap = inFeat.attributes()
idVar = atMap[ self.myParam ]
if idVar.strip() == i.strip():
if idVar == i:
if first:
outID = idVar
first = False
Expand All @@ -506,9 +518,9 @@ def convex_hull(self, useField ):
outGeom = tmpGeom.convexHull()
outFeat.setGeometry( outGeom )
(area, perim) = self.simpleMeasure( outGeom )
outFeat.setAttribute( 0, outID )
outFeat.setAttribute( 1, area )
outFeat.setAttribute( 2, perim )
outFeat.setAttribute( "outID", outID )
outFeat.setAttribute( "area", area )
outFeat.setAttribute( "perim", perim )
writer.addFeature( outFeat )
except:
GEOS_EXCEPT = False
Expand Down Expand Up @@ -547,7 +559,7 @@ def convex_hull(self, useField ):
while fitA.nextFeature( inFeat ):
atMap = inFeat.attributes()
idVar = atMap[ self.myParam ]
if idVar.strip() == i.strip():
if idVar == i:
if first:
outID = idVar
first = False
Expand All @@ -562,9 +574,9 @@ def convex_hull(self, useField ):
outGeom = tmpGeom.convexHull()
outFeat.setGeometry( outGeom )
(area, perim) = self.simpleMeasure( outGeom )
outFeat.setAttribute( 0, outID )
outFeat.setAttribute( 1, area )
outFeat.setAttribute( 2, perim )
outFeat.setAttribute( "outID", outID )
outFeat.setAttribute( "area", area )
outFeat.setAttribute( "perim", perim )
writer.addFeature( outFeat )
except:
GEOS_EXCEPT = False
Expand Down

0 comments on commit b45b7d6

Please sign in to comment.