mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-14 00:07:35 -04:00
Fix #11724 - do to not add extra geometries in union (ftools + processing)
This commit is contained in:
parent
1eaec17369
commit
059fd2c461
@ -1123,9 +1123,8 @@ class geoprocessingThread( QThread ):
|
||||
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 @@ class geoprocessingThread( QThread ):
|
||||
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 @@ class geoprocessingThread( QThread ):
|
||||
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 @@ class geoprocessingThread( QThread ):
|
||||
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 @@ class geoprocessingThread( QThread ):
|
||||
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 @@ class Union(GeoAlgorithm):
|
||||
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 @@ class Union(GeoAlgorithm):
|
||||
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 @@ class Union(GeoAlgorithm):
|
||||
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 @@ class Union(GeoAlgorithm):
|
||||
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 @@ class Union(GeoAlgorithm):
|
||||
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'))
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user