From df79503cae6b72ccfdee774218ca37a03304126f Mon Sep 17 00:00:00 2001 From: Salvatore Larosa Date: Sat, 26 May 2012 14:27:48 +0200 Subject: [PATCH] fix #3549 --- .../plugins/fTools/tools/doGeoprocessing.py | 54 ++++++++++++------- python/plugins/fTools/tools/ftools_utils.py | 8 +++ 2 files changed, 44 insertions(+), 18 deletions(-) diff --git a/python/plugins/fTools/tools/doGeoprocessing.py b/python/plugins/fTools/tools/doGeoprocessing.py index 06afa28f852b..a5dd396ef382 100644 --- a/python/plugins/fTools/tools/doGeoprocessing.py +++ b/python/plugins/fTools/tools/doGeoprocessing.py @@ -970,9 +970,15 @@ def intersect( self ): int_sym = geom.symDifference( tmpGeom ) int_geom = QgsGeometry( int_com.difference( int_sym ) ) try: - outFeat.setGeometry( int_geom ) - outFeat.setAttributeMap( ftools_utils.combineVectorAttributes( atMapA, atMapB ) ) - writer.addFeature( outFeat ) + # Geometry list: prevents writing error + # in geometries of different types + # produced by the intersection + # fix #3549 + gList = ftools_utils.getGeomType( geom.wkbType() ) + if int_geom.wkbType() in gList: + outFeat.setGeometry( int_geom ) + outFeat.setAttributeMap( ftools_utils.combineVectorAttributes( atMapA, atMapB ) ) + writer.addFeature( outFeat ) except: FEATURE_EXCEPT = False continue @@ -999,9 +1005,11 @@ def intersect( self ): int_sym = geom.symDifference( tmpGeom ) int_geom = QgsGeometry( int_com.difference( int_sym ) ) try: - outFeat.setGeometry( int_geom ) - outFeat.setAttributeMap( ftools_utils.combineVectorAttributes( atMapA, atMapB ) ) - writer.addFeature( outFeat ) + gList = ftools_utils.getGeomType( geom.wkbType() ) + if int_geom.wkbType() in gList: + outFeat.setGeometry( int_geom ) + outFeat.setAttributeMap( ftools_utils.combineVectorAttributes( atMapA, atMapB ) ) + writer.addFeature( outFeat ) except: EATURE_EXCEPT = False continue @@ -1037,9 +1045,11 @@ def intersect( self ): int_sym = geom.symDifference( tmpGeom ) int_geom = QgsGeometry( int_com.difference( int_sym ) ) try: - outFeat.setGeometry( int_geom ) - outFeat.setAttributeMap( ftools_utils.combineVectorAttributes( atMapA, atMapB ) ) - writer.addFeature( outFeat ) + gList = ftools_utils.getGeomType( geom.wkbType() ) + if int_geom.wkbType() in gList: + outFeat.setGeometry( int_geom ) + outFeat.setAttributeMap( ftools_utils.combineVectorAttributes( atMapA, atMapB ) ) + writer.addFeature( outFeat ) except: FEATURE_EXCEPT = False continue @@ -1066,9 +1076,11 @@ def intersect( self ): int_sym = geom.symDifference( tmpGeom ) int_geom = QgsGeometry( int_com.difference( int_sym ) ) try: - outFeat.setGeometry( int_geom ) - outFeat.setAttributeMap( ftools_utils.combineVectorAttributes( atMapA, atMapB ) ) - writer.addFeature( outFeat ) + gList = ftools_utils.getGeomType( geom.wkbType() ) + if int_geom.wkbType() in gList: + outFeat.setGeometry( int_geom ) + outFeat.setAttributeMap( ftools_utils.combineVectorAttributes( atMapA, atMapB ) ) + writer.addFeature( outFeat ) except: FEATURE_EXCEPT = False continue @@ -1180,12 +1192,18 @@ def union( self ): except Exception, err: FEATURE_EXCEPT = False else: - try: - outFeat.setGeometry( int_geom ) - outFeat.setAttributeMap( ftools_utils.combineVectorAttributes( atMapA, atMapB ) ) - writer.addFeature( outFeat ) - except Exception, err: - FEATURE_EXCEPT = False + # Geometry list: prevents writing error + # in geometries of different types + # produced by the intersection + # fix #3549 + gList = ftools_utils.getGeomType( geom.wkbType() ) + if int_geom.wkbType() in gList: + try: + outFeat.setGeometry( int_geom ) + outFeat.setAttributeMap( ftools_utils.combineVectorAttributes( atMapA, atMapB ) ) + writer.addFeature( outFeat ) + except Exception, err: + FEATURE_EXCEPT = False else: # this only happends if the bounding box # intersects, but the geometry doesn't diff --git a/python/plugins/fTools/tools/ftools_utils.py b/python/plugins/fTools/tools/ftools_utils.py index c6bd3d5247d1..f69787245622 100644 --- a/python/plugins/fTools/tools/ftools_utils.py +++ b/python/plugins/fTools/tools/ftools_utils.py @@ -344,6 +344,14 @@ def getUniqueValuesCount( vlayer, fieldIndex, useSelection ): count += 1 return count +def getGeomType(gT): + if gT == 3 or gT == 6: + gTypeListPoly = [ QGis.WKBPolygon, QGis.WKBMultiPolygon ] + return gTypeListPoly + elif gT == 2 or gT == 5: + gTypeListLine = [ QGis.WKBLineString, QGis.WKBMultiLineString ] + return gTypeListLine + def getShapesByGeometryType( baseDir, inShapes, geomType ): outShapes = QStringList() for fileName in inShapes: