@@ -12,6 +12,7 @@ def __init__( self, iface, function ):
12
12
QDialog .__init__ ( self )
13
13
self .iface = iface
14
14
self .setupUi ( self )
15
+ self .param .setValidator (QDoubleValidator (self .param ))
15
16
self .myFunction = function
16
17
QObject .connect ( self .btnBrowse , SIGNAL ( "clicked()" ), self .outFile )
17
18
QObject .connect ( self .inShapeA , SIGNAL ( "currentIndexChanged(QString)" ), self .checkA )
@@ -541,12 +542,14 @@ def dissolve( self, useField ):
541
542
vproviderA = self .vlayerA .dataProvider ()
542
543
allAttrsA = vproviderA .attributeIndexes ()
543
544
fields = vproviderA .fields ()
544
- writer = QgsVectorFileWriter ( self .myName , self .myEncoding ,
545
+ writer = QgsVectorFileWriter ( self .myName , self .myEncoding ,
545
546
fields , vproviderA .geometryType (), vproviderA .crs () )
546
547
inFeat = QgsFeature ()
547
548
outFeat = QgsFeature ()
548
549
vproviderA .rewind ()
549
550
nElement = 0
551
+ inGeom = QgsGeometry ()
552
+ geoms = []
550
553
# there is selection in input layer
551
554
if self .mySelectionA :
552
555
nFeat = self .vlayerA .selectedFeatureCount ()
@@ -556,24 +559,21 @@ def dissolve( self, useField ):
556
559
self .emit ( SIGNAL ( "runRange(PyQt_PyObject)" ), ( 0 , nFeat ) )
557
560
first = True
558
561
for inFeat in selectionA :
559
- nElement += 1
562
+ nElement += 0.5
560
563
self .emit ( SIGNAL ( "runStatus(PyQt_PyObject)" ), nElement )
561
564
if first :
562
565
attrs = inFeat .attributeMap ()
563
- tmpInGeom = QgsGeometry ( inFeat .geometry () )
564
- outFeat .setGeometry ( tmpInGeom )
566
+ inGeom = QgsGeometry ( inFeat .geometry () )
565
567
first = False
566
568
else :
567
- tmpInGeom = QgsGeometry ( inFeat .geometry () )
568
- tmpOutGeom = QgsGeometry ( outFeat .geometry () )
569
- try :
570
- tmpOutGeom = QgsGeometry ( tmpOutGeom .combine ( tmpInGeom ) )
571
- outFeat .setGeometry ( tmpOutGeom )
572
- except :
573
- GEOS_EXCEPT = False
574
- continue
575
- outFeat .setAttributeMap ( attrs )
576
- writer .addFeature ( outFeat )
569
+ tmp_geom = QgsGeometry ( inFeat .geometry () )
570
+ geoms .append (tmp_geom )
571
+ outGeom = QgsGeometry (inGeom .combineCascaded (geoms ))
572
+ nElement += nFeat / 2
573
+ self .emit ( SIGNAL ( "runStatus(PyQt_PyObject)" ), nElement )
574
+ outFeat .setGeometry (outGeom )
575
+ outFeat .setAttributeMap (attrs )
576
+ writer .addFeature (outFeat )
577
577
else :
578
578
unique = vproviderA .uniqueValues ( int ( self .myParam ) )
579
579
nFeat = nFeat * len ( unique )
@@ -584,31 +584,25 @@ def dissolve( self, useField ):
584
584
add = False
585
585
vproviderA .select ( allAttrsA )
586
586
vproviderA .rewind ()
587
- for inFeat in selectionA :
588
- nElement += 1
587
+ filtered = [feat for feat in selectionA if feat .attributeMap ()[
588
+ self .myParam ].toString ().trimmed () == item .toString ().trimmed ()]
589
+ for inFeat in filtered :
590
+ nElement += 0.5
589
591
self .emit ( SIGNAL ( "runStatus(PyQt_PyObject)" ), nElement )
590
592
atMap = inFeat .attributeMap ()
591
- tempItem = atMap [ self .myParam ]
592
- if tempItem .toString ().trimmed () == item .toString ().trimmed ():
593
- add = True
594
- if first :
595
- QgsGeometry ( inFeat .geometry () )
596
- tmpInGeom = QgsGeometry ( inFeat .geometry () )
597
- outFeat .setGeometry ( tmpInGeom )
598
- first = False
599
- attrs = inFeat .attributeMap ()
600
- else :
601
- tmpInGeom = QgsGeometry ( inFeat .geometry () )
602
- tmpOutGeom = QgsGeometry ( outFeat .geometry () )
603
- try :
604
- tmpOutGeom = QgsGeometry ( tmpOutGeom .combine ( tmpInGeom ) )
605
- outFeat .setGeometry ( tmpOutGeom )
606
- except :
607
- GEOS_EXCEPT = False
608
- add = False
609
- if add :
610
- outFeat .setAttributeMap ( attrs )
611
- writer .addFeature ( outFeat )
593
+ if first :
594
+ inGeom = QgsGeometry ( inFeat .geometry () )
595
+ first = False
596
+ attrs = inFeat .attributeMap ()
597
+ else :
598
+ tmp_geom = QgsGeometry ( inFeat .geometry () )
599
+ geoms .append (tmp_geom )
600
+ outGeom = QgsGeometry (inGeom .combineCascaded (geoms ))
601
+ nElement += nFeat / 2
602
+ self .emit ( SIGNAL ( "runStatus(PyQt_PyObject)" ), nElement )
603
+ outFeat .setGeometry (outGeom )
604
+ outFeat .setAttributeMap (attrs )
605
+ writer .addFeature (outFeat )
612
606
# there is no selection in input layer
613
607
else :
614
608
nFeat = vproviderA .featureCount ()
@@ -617,58 +611,51 @@ def dissolve( self, useField ):
617
611
self .emit ( SIGNAL ( "runRange(PyQt_PyObject)" ), ( 0 , nFeat ) )
618
612
first = True
619
613
while vproviderA .nextFeature ( inFeat ):
620
- nElement += 1
614
+ nElement += 0.5
621
615
self .emit ( SIGNAL ( "runStatus(PyQt_PyObject)" ), nElement )
622
616
if first :
623
617
attrs = inFeat .attributeMap ()
624
- tmpInGeom = QgsGeometry ( inFeat .geometry () )
625
- outFeat .setGeometry ( tmpInGeom )
618
+ inGeom = QgsGeometry ( inFeat .geometry () )
626
619
first = False
627
620
else :
628
- tmpInGeom = QgsGeometry ( inFeat .geometry () )
629
- tmpOutGeom = QgsGeometry ( outFeat .geometry () )
630
- try :
631
- tmpOutGeom = QgsGeometry ( tmpOutGeom .combine ( tmpInGeom ) )
632
- outFeat .setGeometry ( tmpOutGeom )
633
- except :
634
- GEOS_EXCEPT = False
635
- continue
636
- outFeat .setAttributeMap ( attrs )
637
- writer .addFeature ( outFeat )
621
+ tmp_geom = QgsGeometry ( inFeat .geometry () )
622
+ geoms .append (tmp_geom )
623
+ outGeom = QgsGeometry (inGeom .combineCascaded (geoms ))
624
+ nElement += nFeat / 2
625
+ self .emit ( SIGNAL ( "runStatus(PyQt_PyObject)" ), nElement )
626
+ outFeat .setGeometry (outGeom )
627
+ outFeat .setAttributeMap (attrs )
628
+ writer .addFeature (outFeat )
638
629
else :
639
630
unique = vproviderA .uniqueValues ( int ( self .myParam ) )
640
631
nFeat = nFeat * len ( unique )
641
632
self .emit ( SIGNAL ( "runStatus(PyQt_PyObject)" ), 0 )
642
633
self .emit ( SIGNAL ( "runRange(PyQt_PyObject)" ), ( 0 , nFeat ) )
643
634
for item in unique :
635
+ geoms = []
644
636
first = True
645
637
add = True
646
638
vproviderA .select ( allAttrsA )
647
639
vproviderA .rewind ()
648
640
while vproviderA .nextFeature ( inFeat ):
649
- nElement += 1
641
+ nElement += 0.5
650
642
self .emit ( SIGNAL ( "runStatus(PyQt_PyObject)" ), nElement )
651
643
atMap = inFeat .attributeMap ()
652
644
tempItem = atMap [ self .myParam ]
653
645
if tempItem .toString ().trimmed () == item .toString ().trimmed ():
654
646
if first :
655
- QgsGeometry ( inFeat .geometry () )
656
- tmpInGeom = QgsGeometry ( inFeat .geometry () )
657
- outFeat .setGeometry ( tmpInGeom )
647
+ inGeom = QgsGeometry ( inFeat .geometry () )
658
648
first = False
659
649
attrs = inFeat .attributeMap ()
660
650
else :
661
- tmpInGeom = QgsGeometry ( inFeat .geometry () )
662
- tmpOutGeom = QgsGeometry ( outFeat .geometry () )
663
- try :
664
- tmpOutGeom = QgsGeometry ( tmpOutGeom .combine ( tmpInGeom ) )
665
- outFeat .setGeometry ( tmpOutGeom )
666
- except :
667
- GEOS_EXCEPT = False
668
- add = False
669
- if add :
670
- outFeat .setAttributeMap ( attrs )
671
- writer .addFeature ( outFeat )
651
+ tmp_geom = QgsGeometry ( inFeat .geometry () )
652
+ geoms .append (tmp_geoms )
653
+ outGeom = QgsGeometry (inGeom .combineCascaded (geoms ))
654
+ nElement += nFeat / 2
655
+ self .emit ( SIGNAL ( "runStatus(PyQt_PyObject)" ), nElement )
656
+ outFeat .setGeometry (outGeom )
657
+ outFeat .setAttributeMap (attrs )
658
+ writer .addFeature (outFeat )
672
659
del writer
673
660
return GEOS_EXCEPT , FEATURE_EXCEPT , True
674
661
0 commit comments