@@ -639,40 +639,32 @@ def dissolve( self, useField ):
639
639
outFeat .setAttributeMap ( attrs )
640
640
writer .addFeature ( outFeat )
641
641
else :
642
- unique = vproviderA .uniqueValues ( int ( self .myParam ) )
643
- nFeat = nFeat * len ( unique )
644
- self .emit ( SIGNAL ( "runStatus(PyQt_PyObject)" ), 0 )
642
+ self .emit ( SIGNAL ( "runStatus(PyQt_PyObject)" ), 0 )
645
643
self .emit ( SIGNAL ( "runRange(PyQt_PyObject)" ), ( 0 , nFeat ) )
646
- for item in unique :
647
- first = True
648
- add = False
649
- vproviderA .rewind ()
650
- vproviderA .select ( allAttrsA )
651
- for inFeat in selectionA :
652
- nElement += 1
653
- self .emit ( SIGNAL ( "runStatus(PyQt_PyObject)" ), nElement )
654
- atMap = inFeat .attributeMap ()
655
- tempItem = atMap [ self .myParam ]
656
- if tempItem .toString ().trimmed () == item .toString ().trimmed ():
657
- add = True
658
- if first :
659
- QgsGeometry ( inFeat .geometry () )
660
- tmpInGeom = QgsGeometry ( inFeat .geometry () )
661
- outFeat .setGeometry ( tmpInGeom )
662
- first = False
663
- attrs = inFeat .attributeMap ()
664
- else :
665
- tmpInGeom = QgsGeometry ( inFeat .geometry () )
666
- tmpOutGeom = QgsGeometry ( outFeat .geometry () )
667
- try :
668
- tmpOutGeom = QgsGeometry ( tmpOutGeom .combine ( tmpInGeom ) )
669
- outFeat .setGeometry ( tmpOutGeom )
670
- except :
671
- GEOS_EXCEPT = False
672
- add = False
673
- if add :
674
- outFeat .setAttributeMap ( attrs )
675
- writer .addFeature ( outFeat )
644
+
645
+ outFeats = {}
646
+ attrs = {}
647
+
648
+ for inFeat in selectionA :
649
+ nElement += 1
650
+ self .emit ( SIGNAL ( "runStatus(PyQt_PyObject)" ), nElement )
651
+ atMap = inFeat .attributeMap ()
652
+ tempItem = unicode (atMap [self .myParam ].toString ().trimmed ())
653
+
654
+ if not (tempItem in outFeats ):
655
+ outFeats [tempItem ] = QgsGeometry (inFeat .geometry ())
656
+ attrs [tempItem ] = atMap
657
+ else :
658
+ try :
659
+ outFeats [tempItem ] = outFeats [tempItem ].combine (inFeat .geometry ())
660
+ except :
661
+ GEOS_EXCEPT = False
662
+ continue
663
+ for k in outFeats .keys ():
664
+ feature = QgsFeature ()
665
+ feature .setAttributeMap (attrs [k ])
666
+ feature .setGeometry (outFeats [k ])
667
+ writer .addFeature ( feature )
676
668
# there is no selection in input layer
677
669
else :
678
670
nFeat = vproviderA .featureCount ()
@@ -700,40 +692,32 @@ def dissolve( self, useField ):
700
692
outFeat .setAttributeMap ( attrs )
701
693
writer .addFeature ( outFeat )
702
694
else :
703
- unique = vproviderA .uniqueValues ( int ( self .myParam ) )
704
- nFeat = nFeat * len ( unique )
705
695
self .emit ( SIGNAL ( "runStatus(PyQt_PyObject)" ), 0 )
706
696
self .emit ( SIGNAL ( "runRange(PyQt_PyObject)" ), ( 0 , nFeat ) )
707
- for item in unique :
708
- first = True
709
- add = True
710
- vproviderA .rewind ()
711
- vproviderA .select ( allAttrsA )
712
- while vproviderA .nextFeature ( inFeat ):
713
- nElement += 1
714
- self .emit ( SIGNAL ( "runStatus(PyQt_PyObject)" ), nElement )
715
- atMap = inFeat .attributeMap ()
716
- tempItem = atMap [ self .myParam ]
717
697
718
- if tempItem .toString ().trimmed () == item .toString ().trimmed ():
719
- if first :
720
- QgsGeometry ( inFeat .geometry () )
721
- tmpInGeom = QgsGeometry ( inFeat .geometry () )
722
- outFeat .setGeometry ( tmpInGeom )
723
- first = False
724
- attrs = inFeat .attributeMap ()
725
- else :
726
- tmpInGeom = QgsGeometry ( inFeat .geometry () )
727
- tmpOutGeom = QgsGeometry ( outFeat .geometry () )
728
- try :
729
- tmpOutGeom = QgsGeometry ( tmpOutGeom .combine ( tmpInGeom ) )
730
- outFeat .setGeometry ( tmpOutGeom )
731
- except :
732
- GEOS_EXCEPT = False
733
- add = False
734
- if add :
735
- outFeat .setAttributeMap ( attrs )
736
- writer .addFeature ( outFeat )
698
+ outFeats = {}
699
+ attrs = {}
700
+
701
+ while vproviderA .nextFeature ( inFeat ):
702
+ nElement += 1
703
+ self .emit ( SIGNAL ( "runStatus(PyQt_PyObject)" ), nElement )
704
+ atMap = inFeat .attributeMap ()
705
+ tempItem = unicode (atMap [self .myParam ].toString ().trimmed ())
706
+
707
+ if not (tempItem in outFeats ):
708
+ outFeats [tempItem ] = QgsGeometry (inFeat .geometry ())
709
+ attrs [tempItem ] = atMap
710
+ else :
711
+ try :
712
+ outFeats [tempItem ] = outFeats [tempItem ].combine (inFeat .geometry ())
713
+ except :
714
+ GEOS_EXCEPT = False
715
+ continue
716
+ for k in outFeats .keys ():
717
+ feature = QgsFeature ()
718
+ feature .setAttributeMap (attrs [k ])
719
+ feature .setGeometry (outFeats [k ])
720
+ writer .addFeature ( feature )
737
721
del writer
738
722
return GEOS_EXCEPT , FEATURE_EXCEPT , True , None
739
723
@@ -970,9 +954,9 @@ def intersect( self ):
970
954
int_sym = geom .symDifference ( tmpGeom )
971
955
int_geom = QgsGeometry ( int_com .difference ( int_sym ) )
972
956
try :
973
- # Geometry list: prevents writing error
957
+ # Geometry list: prevents writing error
974
958
# in geometries of different types
975
- # produced by the intersection
959
+ # produced by the intersection
976
960
# fix #3549
977
961
gList = ftools_utils .getGeomType ( geom .wkbType () )
978
962
if int_geom .wkbType () in gList :
@@ -1192,7 +1176,7 @@ def union( self ):
1192
1176
except Exception , err :
1193
1177
FEATURE_EXCEPT = False
1194
1178
else :
1195
- # Geometry list: prevents writing error
1179
+ # Geometry list: prevents writing error
1196
1180
# in geometries of different types
1197
1181
# produced by the intersection
1198
1182
# fix #3549
0 commit comments