Skip to content
Permalink
Browse files

Merge pull request #5188 from nyalldawson/int

[processing] Fix intersection and union tools don't work with input layers with Z or M values present
  • Loading branch information
nyalldawson committed Sep 13, 2017
2 parents c371b72 + bf078b1 commit 2b1cf99e04815d7603b88e1e193f5406d90eb359
Showing with 10 additions and 20 deletions.
  1. +2 −10 python/plugins/processing/algs/qgis/Intersection.py
  2. +8 −10 python/plugins/processing/algs/qgis/Union.py
@@ -46,15 +46,6 @@

pluginPath = os.path.split(os.path.split(os.path.dirname(__file__))[0])[0]

wkbTypeGroups = {
'Point': (QgsWkbTypes.Point, QgsWkbTypes.MultiPoint, QgsWkbTypes.Point25D, QgsWkbTypes.MultiPoint25D,),
'LineString': (QgsWkbTypes.LineString, QgsWkbTypes.MultiLineString, QgsWkbTypes.LineString25D, QgsWkbTypes.MultiLineString25D,),
'Polygon': (QgsWkbTypes.Polygon, QgsWkbTypes.MultiPolygon, QgsWkbTypes.Polygon25D, QgsWkbTypes.MultiPolygon25D,),
}
for key, value in list(wkbTypeGroups.items()):
for const in value:
wkbTypeGroups[const] = key


class Intersection(QgisAlgorithm):

@@ -186,7 +177,8 @@ def processAlgorithm(self, parameters, context, feedback):
'more input features have invalid '
'geometry.'))
try:
if int_geom.wkbType() in wkbTypeGroups[wkbTypeGroups[int_geom.wkbType()]]:
if QgsWkbTypes.geometryType(int_geom.wkbType()) == QgsWkbTypes.geometryType(geomType):
int_geom.convertToMultiType()
outFeat.setGeometry(int_geom)
outFeat.setAttributes(out_attributes)
sink.addFeature(outFeat, QgsFeatureSink.FastInsert)
@@ -44,15 +44,6 @@

pluginPath = os.path.split(os.path.split(os.path.dirname(__file__))[0])[0]

wkbTypeGroups = {
'Point': (QgsWkbTypes.Point, QgsWkbTypes.MultiPoint, QgsWkbTypes.Point25D, QgsWkbTypes.MultiPoint25D,),
'LineString': (QgsWkbTypes.LineString, QgsWkbTypes.MultiLineString, QgsWkbTypes.LineString25D, QgsWkbTypes.MultiLineString25D,),
'Polygon': (QgsWkbTypes.Polygon, QgsWkbTypes.MultiPolygon, QgsWkbTypes.Polygon25D, QgsWkbTypes.MultiPolygon25D,),
}
for key, value in list(wkbTypeGroups.items()):
for const in value:
wkbTypeGroups[const] = key


class Union(QgisAlgorithm):

@@ -113,6 +104,7 @@ def processAlgorithm(self, parameters, context, feedback):
intersects = indexB.intersects(geom.boundingBox())
if len(intersects) < 1:
try:
geom.convertToMultiType()
outFeat.setGeometry(geom)
outFeat.setAttributes(atMapA)
sink.addFeature(outFeat, QgsFeatureSink.FastInsert)
@@ -149,6 +141,7 @@ def processAlgorithm(self, parameters, context, feedback):
if i.type() == geom.type():
int_geom = QgsGeometry(i)
try:
int_geom.convertToMultiType()
outFeat.setGeometry(int_geom)
outFeat.setAttributes(atMapA + atMapB)
sink.addFeature(outFeat, QgsFeatureSink.FastInsert)
@@ -159,8 +152,9 @@ def processAlgorithm(self, parameters, context, feedback):
# in geometries of different types
# produced by the intersection
# fix #3549
if int_geom.wkbType() in wkbTypeGroups[wkbTypeGroups[int_geom.wkbType()]]:
if QgsWkbTypes.geometryType(int_geom.wkbType()) == QgsWkbTypes.geometryType(geomType):
try:
int_geom.convertToMultiType()
outFeat.setGeometry(int_geom)
outFeat.setAttributes(atMapA + atMapB)
sink.addFeature(outFeat, QgsFeatureSink.FastInsert)
@@ -180,6 +174,7 @@ def processAlgorithm(self, parameters, context, feedback):
if i.type() == geom.type():
diff_geom = QgsGeometry(i)
try:
diff_geom.convertToMultiType()
outFeat.setGeometry(diff_geom)
outFeat.setAttributes(atMapA)
sink.addFeature(outFeat, QgsFeatureSink.FastInsert)
@@ -205,6 +200,7 @@ def processAlgorithm(self, parameters, context, feedback):

if len(intersects) < 1:
try:
geom.convertToMultiType()
outFeat.setGeometry(geom)
outFeat.setAttributes(atMap)
sink.addFeature(outFeat, QgsFeatureSink.FastInsert)
@@ -229,6 +225,7 @@ def processAlgorithm(self, parameters, context, feedback):
try:
# Ihis only happens if the bounding box
# intersects, but the geometry doesn't
diff_geom.convertToMultiType()
outFeat.setGeometry(diff_geom)
outFeat.setAttributes(atMap)
sink.addFeature(outFeat, QgsFeatureSink.FastInsert)
@@ -237,6 +234,7 @@ def processAlgorithm(self, parameters, context, feedback):

if add:
try:
diff_geom.convertToMultiType()
outFeat.setGeometry(diff_geom)
outFeat.setAttributes(atMap)
sink.addFeature(outFeat, QgsFeatureSink.FastInsert)

0 comments on commit 2b1cf99

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