Skip to content
Permalink
Browse files

Fix #11724 - do to not add extra geometries in union (ftools + proces…

…sing)
  • Loading branch information
wonder-sk committed Feb 12, 2015
1 parent 1eaec17 commit 059fd2c461b78bf9e5fe8c64e15fa7a957d1b592
Showing with 22 additions and 50 deletions.
  1. +11 −25 python/plugins/fTools/tools/doGeoprocessing.py
  2. +11 −25 python/plugins/processing/algs/qgis/Union.py
@@ -1123,9 +1123,8 @@ def union( self ):
while fitA.nextFeature( inFeatA ):
self.emit( SIGNAL( "runStatus(PyQt_PyObject)" ), nElement )
nElement += 1
found = False
lstIntersectingB = []
geom = QgsGeometry( inFeatA.geometry() )
diff_geom = QgsGeometry( geom )
atMapA = inFeatA.attributes()
intersects = indexA.intersects( geom.boundingBox() )
if len( intersects ) < 1:
@@ -1145,8 +1144,8 @@ def union( self ):
tmpGeom = QgsGeometry( inFeatB.geometry() )
try:
if geom.intersects( tmpGeom ):
found = True
int_geom = geom.intersection( tmpGeom )
lstIntersectingB.append(tmpGeom)

if int_geom is None:
# There was a problem creating the intersection
@@ -1155,14 +1154,6 @@ def union( self ):
else:
int_geom = QgsGeometry(int_geom)

if diff_geom.intersects( tmpGeom ):
diff_geom = diff_geom.difference( tmpGeom )
if diff_geom is None:
# It's possible there was an error here?
diff_geom = QgsGeometry()
else:
diff_geom = QgsGeometry(diff_geom)

if int_geom.wkbType() == 0:
# intersection produced different geometry types
temp_list = int_geom.asGeometryCollection()
@@ -1188,22 +1179,17 @@ def union( self ):
writer.addFeature( outFeat )
except Exception, err:
FEATURE_EXCEPT = False
else:
# this only happends if the bounding box
# intersects, but the geometry doesn't
try:
outFeat.setGeometry( geom )
outFeat.setAttributes( atMapA )
writer.addFeature( outFeat )
except:
# also shoudn't ever happen
FEATURE_EXCEPT = False
except Exception, err:
GEOS_EXCEPT = False
found = False

if found:
try:
try:
# the remaining bit of inFeatA's geometry
# if there is nothing left, this will just silently fail and we're good
diff_geom = QgsGeometry( geom )
if len(lstIntersectingB) != 0:
intB = QgsGeometry.unaryUnion(lstIntersectingB)
diff_geom = diff_geom.difference(intB)

if diff_geom.wkbType() == 0:
temp_list = diff_geom.asGeometryCollection()
for i in temp_list:
@@ -1212,7 +1198,7 @@ def union( self ):
outFeat.setGeometry( diff_geom )
outFeat.setAttributes( atMapA )
writer.addFeature( outFeat )
except Exception, err:
except Exception, err:
FEATURE_EXCEPT = False

length = len( vproviderA.fields() )
@@ -65,9 +65,8 @@ def processAlgorithm(self, progress):
for inFeatA in featuresA:
progress.setPercentage(nElement / float(nFeat) * 50)
nElement += 1
found = False
lstIntersectingB = []
geom = QgsGeometry(inFeatA.geometry())
diff_geom = QgsGeometry(geom)
atMapA = inFeatA.attributes()
intersects = indexA.intersects(geom.boundingBox())
if len(intersects) < 1:
@@ -89,8 +88,8 @@ def processAlgorithm(self, progress):
tmpGeom = QgsGeometry(inFeatB.geometry())

if geom.intersects(tmpGeom):
found = True
int_geom = geom.intersection(tmpGeom)
lstIntersectingB.append(tmpGeom)

if int_geom is None:
# There was a problem creating the intersection
@@ -100,14 +99,6 @@ def processAlgorithm(self, progress):
else:
int_geom = QgsGeometry(int_geom)

if diff_geom.intersects(tmpGeom):
diff_geom = diff_geom.difference(tmpGeom)
if diff_geom is None:
# It's possible there was an error here?
diff_geom = QgsGeometry()
else:
diff_geom = QgsGeometry(diff_geom)

if int_geom.wkbType() == 0:
# Intersection produced different geomety types
temp_list = int_geom.asGeometryCollection()
@@ -124,20 +115,15 @@ def processAlgorithm(self, progress):
except Exception, err:
raise GeoAlgorithmExecutionException(
self.tr('Feature exception while computing union'))
else:
# This only happends if the bounding box intersects,
# but the geometry doesn't
try:
outFeat.setGeometry(geom)
outFeat.setAttributes(atMapA)
writer.addFeature(outFeat)
except:
# Also shoudn't ever happen
raise GeoAlgorithmExecutionException(
self.tr('Feature exception while computing union'))

if found:
try:
try:
# the remaining bit of inFeatA's geometry
# if there is nothing left, this will just silently fail and we're good
diff_geom = QgsGeometry( geom )
if len(lstIntersectingB) != 0:
intB = QgsGeometry.unaryUnion(lstIntersectingB)
diff_geom = diff_geom.difference(intB)

if diff_geom.wkbType() == 0:
temp_list = diff_geom.asGeometryCollection()
for i in temp_list:
@@ -146,7 +132,7 @@ def processAlgorithm(self, progress):
outFeat.setGeometry(diff_geom)
outFeat.setAttributes(atMapA)
writer.addFeature(outFeat)
except Exception, err:
except Exception, err:
raise GeoAlgorithmExecutionException(
self.tr('Feature exception while computing union'))

0 comments on commit 059fd2c

Please sign in to comment.
You can’t perform that action at this time.