@@ -463,13 +463,26 @@ def convex_hull(self, useField ):
463
463
GEOS_EXCEPT = True
464
464
FEATURE_EXCEPT = True
465
465
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 ,
467
477
QGis .WKBPolygon , vproviderA .crs () )
468
478
if writer .hasError ():
469
479
return GEOS_EXCEPT , FEATURE_EXCEPT , True , writer .errorMessage ()
470
480
471
481
inFeat = QgsFeature ()
472
482
outFeat = QgsFeature ()
483
+ # set feature fields
484
+ outFeat .setFields (outFeatFields )
485
+ #
473
486
inGeom = QgsGeometry ()
474
487
outGeom = QgsGeometry ()
475
488
nElement = 0
@@ -487,11 +500,10 @@ def convex_hull(self, useField ):
487
500
hull = []
488
501
first = True
489
502
outID = 0
490
- vproviderA .rewind ()
491
503
for inFeat in selectionA :
492
504
atMap = inFeat .attributes ()
493
505
idVar = atMap [ self .myParam ]
494
- if idVar . strip () == i . strip () :
506
+ if idVar == i :
495
507
if first :
496
508
outID = idVar
497
509
first = False
@@ -506,9 +518,9 @@ def convex_hull(self, useField ):
506
518
outGeom = tmpGeom .convexHull ()
507
519
outFeat .setGeometry ( outGeom )
508
520
(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 )
512
524
writer .addFeature ( outFeat )
513
525
except :
514
526
GEOS_EXCEPT = False
@@ -547,7 +559,7 @@ def convex_hull(self, useField ):
547
559
while fitA .nextFeature ( inFeat ):
548
560
atMap = inFeat .attributes ()
549
561
idVar = atMap [ self .myParam ]
550
- if idVar . strip () == i . strip () :
562
+ if idVar == i :
551
563
if first :
552
564
outID = idVar
553
565
first = False
@@ -562,9 +574,9 @@ def convex_hull(self, useField ):
562
574
outGeom = tmpGeom .convexHull ()
563
575
outFeat .setGeometry ( outGeom )
564
576
(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 )
568
580
writer .addFeature ( outFeat )
569
581
except :
570
582
GEOS_EXCEPT = False
0 commit comments