Skip to content

Commit

Permalink
Merge pull request #5188 from nyalldawson/int
Browse files Browse the repository at this point in the history
[processing] Fix intersection and union tools don't work with input layers with Z or M values present
  • Loading branch information
nyalldawson authored Sep 13, 2017
2 parents c371b72 + bf078b1 commit 2b1cf99
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 20 deletions.
12 changes: 2 additions & 10 deletions python/plugins/processing/algs/qgis/Intersection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):

Expand Down Expand Up @@ -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)
Expand Down
18 changes: 8 additions & 10 deletions python/plugins/processing/algs/qgis/Union.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit 2b1cf99

Please sign in to comment.