Skip to content

Commit b45b7d6

Browse files
committed
Merge pull request #712 from ddanielvaz/fix-8219
Fix 8219
2 parents b50a893 + 522aecc commit b45b7d6

File tree

1 file changed

+22
-10
lines changed

1 file changed

+22
-10
lines changed

python/plugins/fTools/tools/doGeoprocessing.py

+22-10
Original file line numberDiff line numberDiff line change
@@ -463,13 +463,26 @@ def convex_hull(self, useField ):
463463
GEOS_EXCEPT = True
464464
FEATURE_EXCEPT = True
465465
vproviderA = self.vlayerA.dataProvider()
466-
writer = QgsVectorFileWriter( self.myName, self.myEncoding, vproviderA.fields(),
466+
# creating fields
467+
idField = QgsField("outID", QVariant.String)
468+
areaField = QgsField("area", QVariant.Double)
469+
perimField = QgsField("perim", QVariant.Double)
470+
# appending fields
471+
outFeatFields = QgsFields()
472+
outFeatFields.append(idField)
473+
outFeatFields.append(areaField)
474+
outFeatFields.append(perimField)
475+
#
476+
writer = QgsVectorFileWriter( self.myName, self.myEncoding, outFeatFields,
467477
QGis.WKBPolygon, vproviderA.crs() )
468478
if writer.hasError():
469479
return GEOS_EXCEPT, FEATURE_EXCEPT, True, writer.errorMessage()
470480

471481
inFeat = QgsFeature()
472482
outFeat = QgsFeature()
483+
# set feature fields
484+
outFeat.setFields(outFeatFields)
485+
#
473486
inGeom = QgsGeometry()
474487
outGeom = QgsGeometry()
475488
nElement = 0
@@ -487,11 +500,10 @@ def convex_hull(self, useField ):
487500
hull = []
488501
first = True
489502
outID = 0
490-
vproviderA.rewind()
491503
for inFeat in selectionA:
492504
atMap = inFeat.attributes()
493505
idVar = atMap[ self.myParam ]
494-
if idVar.strip() == i.strip():
506+
if idVar == i:
495507
if first:
496508
outID = idVar
497509
first = False
@@ -506,9 +518,9 @@ def convex_hull(self, useField ):
506518
outGeom = tmpGeom.convexHull()
507519
outFeat.setGeometry( outGeom )
508520
(area, perim) = self.simpleMeasure( outGeom )
509-
outFeat.setAttribute( 0, outID )
510-
outFeat.setAttribute( 1, area )
511-
outFeat.setAttribute( 2, perim )
521+
outFeat.setAttribute( "outID", outID )
522+
outFeat.setAttribute( "area", area )
523+
outFeat.setAttribute( "perim", perim )
512524
writer.addFeature( outFeat )
513525
except:
514526
GEOS_EXCEPT = False
@@ -547,7 +559,7 @@ def convex_hull(self, useField ):
547559
while fitA.nextFeature( inFeat ):
548560
atMap = inFeat.attributes()
549561
idVar = atMap[ self.myParam ]
550-
if idVar.strip() == i.strip():
562+
if idVar == i:
551563
if first:
552564
outID = idVar
553565
first = False
@@ -562,9 +574,9 @@ def convex_hull(self, useField ):
562574
outGeom = tmpGeom.convexHull()
563575
outFeat.setGeometry( outGeom )
564576
(area, perim) = self.simpleMeasure( outGeom )
565-
outFeat.setAttribute( 0, outID )
566-
outFeat.setAttribute( 1, area )
567-
outFeat.setAttribute( 2, perim )
577+
outFeat.setAttribute( "outID", outID )
578+
outFeat.setAttribute( "area", area )
579+
outFeat.setAttribute( "perim", perim )
568580
writer.addFeature( outFeat )
569581
except:
570582
GEOS_EXCEPT = False

0 commit comments

Comments
 (0)