Skip to content

Commit

Permalink
Fix #11724 - do to not add extra geometries in union (ftools + proces…
Browse files Browse the repository at this point in the history
…sing)
  • Loading branch information
wonder-sk committed Feb 12, 2015
1 parent 1eaec17 commit 059fd2c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 50 deletions.
36 changes: 11 additions & 25 deletions python/plugins/fTools/tools/doGeoprocessing.py
Expand Up @@ -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:
Expand All @@ -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
Expand All @@ -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()
Expand All @@ -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:
Expand All @@ -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() )
Expand Down
36 changes: 11 additions & 25 deletions python/plugins/processing/algs/qgis/Union.py
Expand Up @@ -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:
Expand All @@ -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
Expand All @@ -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()
Expand All @@ -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:
Expand All @@ -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'))

Expand Down

0 comments on commit 059fd2c

Please sign in to comment.