Skip to content

Commit 43d89d9

Browse files
author
cfarmer
committed
Restore previous version of dissolve function (previous changes should not have been commited yet.
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@13315 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 91bc447 commit 43d89d9

File tree

1 file changed

+65
-51
lines changed

1 file changed

+65
-51
lines changed

python/plugins/fTools/tools/doGeoprocessing.py

+65-51
Original file line numberDiff line numberDiff line change
@@ -542,14 +542,12 @@ def dissolve( self, useField ):
542542
vproviderA = self.vlayerA.dataProvider()
543543
allAttrsA = vproviderA.attributeIndexes()
544544
fields = vproviderA.fields()
545-
writer = QgsVectorFileWriter( self.myName, self.myEncoding,
545+
writer = QgsVectorFileWriter( self.myName, self.myEncoding,
546546
fields, vproviderA.geometryType(), vproviderA.crs() )
547547
inFeat = QgsFeature()
548548
outFeat = QgsFeature()
549549
vproviderA.rewind()
550550
nElement = 0
551-
inGeom = QgsGeometry()
552-
geoms = []
553551
# there is selection in input layer
554552
if self.mySelectionA:
555553
nFeat = self.vlayerA.selectedFeatureCount()
@@ -559,21 +557,24 @@ def dissolve( self, useField ):
559557
self.emit( SIGNAL( "runRange(PyQt_PyObject)" ), ( 0, nFeat ) )
560558
first = True
561559
for inFeat in selectionA:
562-
nElement += 0.5
560+
nElement += 1
563561
self.emit( SIGNAL( "runStatus(PyQt_PyObject)" ), nElement )
564562
if first:
565563
attrs = inFeat.attributeMap()
566-
inGeom = QgsGeometry( inFeat.geometry() )
564+
tmpInGeom = QgsGeometry( inFeat.geometry() )
565+
outFeat.setGeometry( tmpInGeom )
567566
first = False
568567
else:
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)
568+
tmpInGeom = QgsGeometry( inFeat.geometry() )
569+
tmpOutGeom = QgsGeometry( outFeat.geometry() )
570+
try:
571+
tmpOutGeom = QgsGeometry( tmpOutGeom.combine( tmpInGeom ) )
572+
outFeat.setGeometry( tmpOutGeom )
573+
except:
574+
GEOS_EXCEPT = False
575+
continue
576+
outFeat.setAttributeMap( attrs )
577+
writer.addFeature( outFeat )
577578
else:
578579
unique = vproviderA.uniqueValues( int( self.myParam ) )
579580
nFeat = nFeat * len( unique )
@@ -584,25 +585,31 @@ def dissolve( self, useField ):
584585
add = False
585586
vproviderA.select( allAttrsA )
586587
vproviderA.rewind()
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
588+
for inFeat in selectionA:
589+
nElement += 1
591590
self.emit( SIGNAL( "runStatus(PyQt_PyObject)" ), nElement )
592591
atMap = inFeat.attributeMap()
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)
592+
tempItem = atMap[ self.myParam ]
593+
if tempItem.toString().trimmed() == item.toString().trimmed():
594+
add = True
595+
if first:
596+
QgsGeometry( inFeat.geometry() )
597+
tmpInGeom = QgsGeometry( inFeat.geometry() )
598+
outFeat.setGeometry( tmpInGeom )
599+
first = False
600+
attrs = inFeat.attributeMap()
601+
else:
602+
tmpInGeom = QgsGeometry( inFeat.geometry() )
603+
tmpOutGeom = QgsGeometry( outFeat.geometry() )
604+
try:
605+
tmpOutGeom = QgsGeometry( tmpOutGeom.combine( tmpInGeom ) )
606+
outFeat.setGeometry( tmpOutGeom )
607+
except:
608+
GEOS_EXCEPT = False
609+
add = False
610+
if add:
611+
outFeat.setAttributeMap( attrs )
612+
writer.addFeature( outFeat )
606613
# there is no selection in input layer
607614
else:
608615
nFeat = vproviderA.featureCount()
@@ -611,51 +618,58 @@ def dissolve( self, useField ):
611618
self.emit( SIGNAL( "runRange(PyQt_PyObject)" ), ( 0, nFeat ) )
612619
first = True
613620
while vproviderA.nextFeature( inFeat ):
614-
nElement += 0.5
621+
nElement += 1
615622
self.emit( SIGNAL( "runStatus(PyQt_PyObject)" ), nElement )
616623
if first:
617624
attrs = inFeat.attributeMap()
618-
inGeom = QgsGeometry( inFeat.geometry() )
625+
tmpInGeom = QgsGeometry( inFeat.geometry() )
626+
outFeat.setGeometry( tmpInGeom )
619627
first = False
620628
else:
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)
629+
tmpInGeom = QgsGeometry( inFeat.geometry() )
630+
tmpOutGeom = QgsGeometry( outFeat.geometry() )
631+
try:
632+
tmpOutGeom = QgsGeometry( tmpOutGeom.combine( tmpInGeom ) )
633+
outFeat.setGeometry( tmpOutGeom )
634+
except:
635+
GEOS_EXCEPT = False
636+
continue
637+
outFeat.setAttributeMap( attrs )
638+
writer.addFeature( outFeat )
629639
else:
630640
unique = vproviderA.uniqueValues( int( self.myParam ) )
631641
nFeat = nFeat * len( unique )
632642
self.emit( SIGNAL( "runStatus(PyQt_PyObject)" ), 0)
633643
self.emit( SIGNAL( "runRange(PyQt_PyObject)" ), ( 0, nFeat ) )
634644
for item in unique:
635-
geoms = []
636645
first = True
637646
add = True
638647
vproviderA.select( allAttrsA )
639648
vproviderA.rewind()
640649
while vproviderA.nextFeature( inFeat ):
641-
nElement += 0.5
650+
nElement += 1
642651
self.emit( SIGNAL( "runStatus(PyQt_PyObject)" ), nElement )
643652
atMap = inFeat.attributeMap()
644653
tempItem = atMap[ self.myParam ]
645654
if tempItem.toString().trimmed() == item.toString().trimmed():
646655
if first:
647-
inGeom = QgsGeometry( inFeat.geometry() )
656+
QgsGeometry( inFeat.geometry() )
657+
tmpInGeom = QgsGeometry( inFeat.geometry() )
658+
outFeat.setGeometry( tmpInGeom )
648659
first = False
649660
attrs = inFeat.attributeMap()
650661
else:
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)
662+
tmpInGeom = QgsGeometry( inFeat.geometry() )
663+
tmpOutGeom = QgsGeometry( outFeat.geometry() )
664+
try:
665+
tmpOutGeom = QgsGeometry( tmpOutGeom.combine( tmpInGeom ) )
666+
outFeat.setGeometry( tmpOutGeom )
667+
except:
668+
GEOS_EXCEPT = False
669+
add = False
670+
if add:
671+
outFeat.setAttributeMap( attrs )
672+
writer.addFeature( outFeat )
659673
del writer
660674
return GEOS_EXCEPT, FEATURE_EXCEPT, True
661675

0 commit comments

Comments
 (0)