@@ -463,16 +463,25 @@ def convex_hull(self, useField ):
463
463
GEOS_EXCEPT = True
464
464
FEATURE_EXCEPT = True
465
465
vproviderA = self .vlayerA .dataProvider ()
466
+ #
467
+ outFeatFields = QgsFields ()
468
+ if useField :
469
+ importedField = vproviderA .fields ().at ( self .myParam )
470
+ outFeatFields .append ( importedField )
471
+ #
472
+ importedFieldName = importedField .name ( )
473
+ else :
474
+ outIdField = QgsField ( "hullGeneratedID" , QVariant .String )
475
+ outFeatFields .append ( outIdField )
466
476
# creating fields
467
- idField = QgsField ("outID" , QVariant .String )
468
477
areaField = QgsField ("area" , QVariant .Double )
469
478
perimField = QgsField ("perim" , QVariant .Double )
470
479
# appending fields
471
- outFeatFields = QgsFields ()
472
- outFeatFields .append (idField )
473
480
outFeatFields .append (areaField )
474
481
outFeatFields .append (perimField )
475
482
#
483
+ outFeatFields .extend ( vproviderA .fields () )
484
+ #
476
485
writer = QgsVectorFileWriter ( self .myName , self .myEncoding , outFeatFields ,
477
486
QGis .WKBPolygon , vproviderA .crs () )
478
487
if writer .hasError ():
@@ -497,15 +506,14 @@ def convex_hull(self, useField ):
497
506
self .emit ( SIGNAL ( "runStatus(PyQt_PyObject)" ), 0 )
498
507
self .emit ( SIGNAL ( "runRange(PyQt_PyObject)" ), ( 0 , nFeat ) )
499
508
for i in unique :
500
- hull = []
501
509
first = True
502
- outID = 0
510
+ hull = []
503
511
for inFeat in selectionA :
504
512
atMap = inFeat .attributes ()
505
513
idVar = atMap [ self .myParam ]
506
514
if idVar == i :
507
515
if first :
508
- outID = idVar
516
+ firstFeature = QgsFeature ( inFeat )
509
517
first = False
510
518
inGeom = QgsGeometry ( inFeat .geometry () )
511
519
points = ftools_utils .extractPoints ( inGeom )
@@ -518,7 +526,8 @@ def convex_hull(self, useField ):
518
526
outGeom = tmpGeom .convexHull ()
519
527
outFeat .setGeometry ( outGeom )
520
528
(area , perim ) = self .simpleMeasure ( outGeom )
521
- outFeat .setAttribute ( "outID" , outID )
529
+ for f in firstFeature .fields ():
530
+ outFeat .setAttribute ( f .name ( ), firstFeature .attribute ( f .name ( ) ) )
522
531
outFeat .setAttribute ( "area" , area )
523
532
outFeat .setAttribute ( "perim" , perim )
524
533
writer .addFeature ( outFeat )
@@ -539,6 +548,12 @@ def convex_hull(self, useField ):
539
548
try :
540
549
outGeom = tmpGeom .convexHull ()
541
550
outFeat .setGeometry ( outGeom )
551
+ (area , perim ) = self .simpleMeasure ( outGeom )
552
+ for f in inFeat .fields ():
553
+ outFeat .setAttribute ( f .name ( ), inFeat .attribute ( f .name ( ) ) )
554
+ outFeat .setAttribute ( "hullGeneratedID" , 'hullPolygonGenerated' )
555
+ outFeat .setAttribute ( "area" , area )
556
+ outFeat .setAttribute ( "perim" , perim )
542
557
writer .addFeature ( outFeat )
543
558
except :
544
559
GEOS_EXCEPT = False
@@ -550,18 +565,16 @@ def convex_hull(self, useField ):
550
565
nFeat = nFeat * len ( unique )
551
566
self .emit ( SIGNAL ( "runStatus(PyQt_PyObject)" ), 0 )
552
567
self .emit ( SIGNAL ( "runRange(PyQt_PyObject)" ), ( 0 , nFeat ) )
568
+
553
569
for i in unique :
554
- hull = []
555
570
first = True
556
- outID = 0
557
-
571
+ hull = []
558
572
fitA = vproviderA .getFeatures ()
559
573
while fitA .nextFeature ( inFeat ):
560
- atMap = inFeat .attributes ()
561
- idVar = atMap [ self .myParam ]
574
+ idVar = inFeat .attribute ( importedFieldName )
562
575
if idVar == i :
563
576
if first :
564
- outID = idVar
577
+ firstFeature = QgsFeature ( inFeat )
565
578
first = False
566
579
inGeom = QgsGeometry ( inFeat .geometry () )
567
580
points = ftools_utils .extractPoints ( inGeom )
@@ -574,7 +587,8 @@ def convex_hull(self, useField ):
574
587
outGeom = tmpGeom .convexHull ()
575
588
outFeat .setGeometry ( outGeom )
576
589
(area , perim ) = self .simpleMeasure ( outGeom )
577
- outFeat .setAttribute ( "outID" , outID )
590
+ for f in firstFeature .fields ():
591
+ outFeat .setAttribute ( f .name ( ), firstFeature .attribute ( f .name ( ) ) )
578
592
outFeat .setAttribute ( "area" , area )
579
593
outFeat .setAttribute ( "perim" , perim )
580
594
writer .addFeature ( outFeat )
@@ -596,6 +610,12 @@ def convex_hull(self, useField ):
596
610
try :
597
611
outGeom = tmpGeom .convexHull ()
598
612
outFeat .setGeometry ( outGeom )
613
+ (area , perim ) = self .simpleMeasure ( outGeom )
614
+ for f in inFeat .fields ():
615
+ outFeat .setAttribute ( f .name ( ), inFeat .attribute ( f .name ( ) ) )
616
+ outFeat .setAttribute ( "hullGeneratedID" , 'hullPolygonGenerated' )
617
+ outFeat .setAttribute ( "area" , area )
618
+ outFeat .setAttribute ( "perim" , perim )
599
619
writer .addFeature ( outFeat )
600
620
except :
601
621
GEOS_EXCEPT = False
0 commit comments