mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-15 00:04:00 -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 ):
|
while fitA.nextFeature( inFeatA ):
|
||||||
self.emit( SIGNAL( "runStatus(PyQt_PyObject)" ), nElement )
|
self.emit( SIGNAL( "runStatus(PyQt_PyObject)" ), nElement )
|
||||||
nElement += 1
|
nElement += 1
|
||||||
found = False
|
lstIntersectingB = []
|
||||||
geom = QgsGeometry( inFeatA.geometry() )
|
geom = QgsGeometry( inFeatA.geometry() )
|
||||||
diff_geom = QgsGeometry( geom )
|
|
||||||
atMapA = inFeatA.attributes()
|
atMapA = inFeatA.attributes()
|
||||||
intersects = indexA.intersects( geom.boundingBox() )
|
intersects = indexA.intersects( geom.boundingBox() )
|
||||||
if len( intersects ) < 1:
|
if len( intersects ) < 1:
|
||||||
@ -1145,8 +1144,8 @@ class geoprocessingThread( QThread ):
|
|||||||
tmpGeom = QgsGeometry( inFeatB.geometry() )
|
tmpGeom = QgsGeometry( inFeatB.geometry() )
|
||||||
try:
|
try:
|
||||||
if geom.intersects( tmpGeom ):
|
if geom.intersects( tmpGeom ):
|
||||||
found = True
|
|
||||||
int_geom = geom.intersection( tmpGeom )
|
int_geom = geom.intersection( tmpGeom )
|
||||||
|
lstIntersectingB.append(tmpGeom)
|
||||||
|
|
||||||
if int_geom is None:
|
if int_geom is None:
|
||||||
# There was a problem creating the intersection
|
# There was a problem creating the intersection
|
||||||
@ -1155,14 +1154,6 @@ class geoprocessingThread( QThread ):
|
|||||||
else:
|
else:
|
||||||
int_geom = QgsGeometry(int_geom)
|
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:
|
if int_geom.wkbType() == 0:
|
||||||
# intersection produced different geometry types
|
# intersection produced different geometry types
|
||||||
temp_list = int_geom.asGeometryCollection()
|
temp_list = int_geom.asGeometryCollection()
|
||||||
@ -1188,22 +1179,17 @@ class geoprocessingThread( QThread ):
|
|||||||
writer.addFeature( outFeat )
|
writer.addFeature( outFeat )
|
||||||
except Exception, err:
|
except Exception, err:
|
||||||
FEATURE_EXCEPT = False
|
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:
|
except Exception, err:
|
||||||
GEOS_EXCEPT = False
|
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:
|
if diff_geom.wkbType() == 0:
|
||||||
temp_list = diff_geom.asGeometryCollection()
|
temp_list = diff_geom.asGeometryCollection()
|
||||||
for i in temp_list:
|
for i in temp_list:
|
||||||
@ -1212,7 +1198,7 @@ class geoprocessingThread( QThread ):
|
|||||||
outFeat.setGeometry( diff_geom )
|
outFeat.setGeometry( diff_geom )
|
||||||
outFeat.setAttributes( atMapA )
|
outFeat.setAttributes( atMapA )
|
||||||
writer.addFeature( outFeat )
|
writer.addFeature( outFeat )
|
||||||
except Exception, err:
|
except Exception, err:
|
||||||
FEATURE_EXCEPT = False
|
FEATURE_EXCEPT = False
|
||||||
|
|
||||||
length = len( vproviderA.fields() )
|
length = len( vproviderA.fields() )
|
||||||
|
@ -65,9 +65,8 @@ class Union(GeoAlgorithm):
|
|||||||
for inFeatA in featuresA:
|
for inFeatA in featuresA:
|
||||||
progress.setPercentage(nElement / float(nFeat) * 50)
|
progress.setPercentage(nElement / float(nFeat) * 50)
|
||||||
nElement += 1
|
nElement += 1
|
||||||
found = False
|
lstIntersectingB = []
|
||||||
geom = QgsGeometry(inFeatA.geometry())
|
geom = QgsGeometry(inFeatA.geometry())
|
||||||
diff_geom = QgsGeometry(geom)
|
|
||||||
atMapA = inFeatA.attributes()
|
atMapA = inFeatA.attributes()
|
||||||
intersects = indexA.intersects(geom.boundingBox())
|
intersects = indexA.intersects(geom.boundingBox())
|
||||||
if len(intersects) < 1:
|
if len(intersects) < 1:
|
||||||
@ -89,8 +88,8 @@ class Union(GeoAlgorithm):
|
|||||||
tmpGeom = QgsGeometry(inFeatB.geometry())
|
tmpGeom = QgsGeometry(inFeatB.geometry())
|
||||||
|
|
||||||
if geom.intersects(tmpGeom):
|
if geom.intersects(tmpGeom):
|
||||||
found = True
|
|
||||||
int_geom = geom.intersection(tmpGeom)
|
int_geom = geom.intersection(tmpGeom)
|
||||||
|
lstIntersectingB.append(tmpGeom)
|
||||||
|
|
||||||
if int_geom is None:
|
if int_geom is None:
|
||||||
# There was a problem creating the intersection
|
# There was a problem creating the intersection
|
||||||
@ -100,14 +99,6 @@ class Union(GeoAlgorithm):
|
|||||||
else:
|
else:
|
||||||
int_geom = QgsGeometry(int_geom)
|
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:
|
if int_geom.wkbType() == 0:
|
||||||
# Intersection produced different geomety types
|
# Intersection produced different geomety types
|
||||||
temp_list = int_geom.asGeometryCollection()
|
temp_list = int_geom.asGeometryCollection()
|
||||||
@ -124,20 +115,15 @@ class Union(GeoAlgorithm):
|
|||||||
except Exception, err:
|
except Exception, err:
|
||||||
raise GeoAlgorithmExecutionException(
|
raise GeoAlgorithmExecutionException(
|
||||||
self.tr('Feature exception while computing union'))
|
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:
|
if diff_geom.wkbType() == 0:
|
||||||
temp_list = diff_geom.asGeometryCollection()
|
temp_list = diff_geom.asGeometryCollection()
|
||||||
for i in temp_list:
|
for i in temp_list:
|
||||||
@ -146,7 +132,7 @@ class Union(GeoAlgorithm):
|
|||||||
outFeat.setGeometry(diff_geom)
|
outFeat.setGeometry(diff_geom)
|
||||||
outFeat.setAttributes(atMapA)
|
outFeat.setAttributes(atMapA)
|
||||||
writer.addFeature(outFeat)
|
writer.addFeature(outFeat)
|
||||||
except Exception, err:
|
except Exception, err:
|
||||||
raise GeoAlgorithmExecutionException(
|
raise GeoAlgorithmExecutionException(
|
||||||
self.tr('Feature exception while computing union'))
|
self.tr('Feature exception while computing union'))
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user