Skip to content

Commit bb9c989

Browse files
Fixed bug in the processing toolbox qgis:intersection tool, preventing
attempts at writing the wrong geometry type to a shapefile.
1 parent a31ebb4 commit bb9c989

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

python/plugins/processing/algs/ftools/Intersection.py

+16-7
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,14 @@
3333
from processing.outputs.OutputVector import OutputVector
3434
from processing.tools import dataobjects, vector
3535

36+
wkbTypeGroups = {
37+
'Point': (QGis.WKBPoint, QGis.WKBMultiPoint, QGis.WKBPoint25D, QGis.WKBMultiPoint25D,),
38+
'LineString': (QGis.WKBLineString, QGis.WKBMultiLineString, QGis.WKBLineString25D, QGis.WKBMultiLineString25D,),
39+
'Polygon': (QGis.WKBPolygon, QGis.WKBMultiPolygon, QGis.WKBPolygon25D, QGis.WKBMultiPolygon25D,),
40+
}
41+
for key, value in wkbTypeGroups.items():
42+
for const in value:
43+
wkbTypeGroups[const] = key
3644

3745
class Intersection(GeoAlgorithm):
3846

@@ -70,16 +78,17 @@ def processAlgorithm(self, progress):
7078
if geom.intersects(tmpGeom):
7179
atMapB = inFeatB.attributes()
7280
int_geom = QgsGeometry(geom.intersection(tmpGeom))
73-
if int_geom.wkbType() == 7:
81+
if int_geom.wkbType() == QGis.WKBUnknown:
7482
int_com = geom.combine(tmpGeom)
7583
int_sym = geom.symDifference(tmpGeom)
7684
int_geom = QgsGeometry(int_com.difference(int_sym))
77-
outFeat.setGeometry(int_geom)
78-
attrs = []
79-
attrs.extend(atMapA)
80-
attrs.extend(atMapB)
81-
outFeat.setAttributes(attrs)
82-
writer.addFeature(outFeat)
85+
if int_geom.wkbType() in wkbTypeGroups[wkbTypeGroups[int_geom.wkbType()]]:
86+
outFeat.setGeometry(int_geom)
87+
attrs = []
88+
attrs.extend(atMapA)
89+
attrs.extend(atMapB)
90+
outFeat.setAttributes(attrs)
91+
writer.addFeature(outFeat)
8392

8493
del writer
8594

0 commit comments

Comments
 (0)