Skip to content

Commit 4295a68

Browse files
committed
Merge pull request #150 from slarosa/master
fix #3549
2 parents 9d0745f + df79503 commit 4295a68

File tree

2 files changed

+44
-18
lines changed

2 files changed

+44
-18
lines changed

python/plugins/fTools/tools/doGeoprocessing.py

+36-18
Original file line numberDiff line numberDiff line change
@@ -970,9 +970,15 @@ def intersect( self ):
970970
int_sym = geom.symDifference( tmpGeom )
971971
int_geom = QgsGeometry( int_com.difference( int_sym ) )
972972
try:
973-
outFeat.setGeometry( int_geom )
974-
outFeat.setAttributeMap( ftools_utils.combineVectorAttributes( atMapA, atMapB ) )
975-
writer.addFeature( outFeat )
973+
# Geometry list: prevents writing error
974+
# in geometries of different types
975+
# produced by the intersection
976+
# fix #3549
977+
gList = ftools_utils.getGeomType( geom.wkbType() )
978+
if int_geom.wkbType() in gList:
979+
outFeat.setGeometry( int_geom )
980+
outFeat.setAttributeMap( ftools_utils.combineVectorAttributes( atMapA, atMapB ) )
981+
writer.addFeature( outFeat )
976982
except:
977983
FEATURE_EXCEPT = False
978984
continue
@@ -999,9 +1005,11 @@ def intersect( self ):
9991005
int_sym = geom.symDifference( tmpGeom )
10001006
int_geom = QgsGeometry( int_com.difference( int_sym ) )
10011007
try:
1002-
outFeat.setGeometry( int_geom )
1003-
outFeat.setAttributeMap( ftools_utils.combineVectorAttributes( atMapA, atMapB ) )
1004-
writer.addFeature( outFeat )
1008+
gList = ftools_utils.getGeomType( geom.wkbType() )
1009+
if int_geom.wkbType() in gList:
1010+
outFeat.setGeometry( int_geom )
1011+
outFeat.setAttributeMap( ftools_utils.combineVectorAttributes( atMapA, atMapB ) )
1012+
writer.addFeature( outFeat )
10051013
except:
10061014
EATURE_EXCEPT = False
10071015
continue
@@ -1037,9 +1045,11 @@ def intersect( self ):
10371045
int_sym = geom.symDifference( tmpGeom )
10381046
int_geom = QgsGeometry( int_com.difference( int_sym ) )
10391047
try:
1040-
outFeat.setGeometry( int_geom )
1041-
outFeat.setAttributeMap( ftools_utils.combineVectorAttributes( atMapA, atMapB ) )
1042-
writer.addFeature( outFeat )
1048+
gList = ftools_utils.getGeomType( geom.wkbType() )
1049+
if int_geom.wkbType() in gList:
1050+
outFeat.setGeometry( int_geom )
1051+
outFeat.setAttributeMap( ftools_utils.combineVectorAttributes( atMapA, atMapB ) )
1052+
writer.addFeature( outFeat )
10431053
except:
10441054
FEATURE_EXCEPT = False
10451055
continue
@@ -1066,9 +1076,11 @@ def intersect( self ):
10661076
int_sym = geom.symDifference( tmpGeom )
10671077
int_geom = QgsGeometry( int_com.difference( int_sym ) )
10681078
try:
1069-
outFeat.setGeometry( int_geom )
1070-
outFeat.setAttributeMap( ftools_utils.combineVectorAttributes( atMapA, atMapB ) )
1071-
writer.addFeature( outFeat )
1079+
gList = ftools_utils.getGeomType( geom.wkbType() )
1080+
if int_geom.wkbType() in gList:
1081+
outFeat.setGeometry( int_geom )
1082+
outFeat.setAttributeMap( ftools_utils.combineVectorAttributes( atMapA, atMapB ) )
1083+
writer.addFeature( outFeat )
10721084
except:
10731085
FEATURE_EXCEPT = False
10741086
continue
@@ -1180,12 +1192,18 @@ def union( self ):
11801192
except Exception, err:
11811193
FEATURE_EXCEPT = False
11821194
else:
1183-
try:
1184-
outFeat.setGeometry( int_geom )
1185-
outFeat.setAttributeMap( ftools_utils.combineVectorAttributes( atMapA, atMapB ) )
1186-
writer.addFeature( outFeat )
1187-
except Exception, err:
1188-
FEATURE_EXCEPT = False
1195+
# Geometry list: prevents writing error
1196+
# in geometries of different types
1197+
# produced by the intersection
1198+
# fix #3549
1199+
gList = ftools_utils.getGeomType( geom.wkbType() )
1200+
if int_geom.wkbType() in gList:
1201+
try:
1202+
outFeat.setGeometry( int_geom )
1203+
outFeat.setAttributeMap( ftools_utils.combineVectorAttributes( atMapA, atMapB ) )
1204+
writer.addFeature( outFeat )
1205+
except Exception, err:
1206+
FEATURE_EXCEPT = False
11891207
else:
11901208
# this only happends if the bounding box
11911209
# intersects, but the geometry doesn't

python/plugins/fTools/tools/ftools_utils.py

+8
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,14 @@ def getUniqueValuesCount( vlayer, fieldIndex, useSelection ):
344344
count += 1
345345
return count
346346

347+
def getGeomType(gT):
348+
if gT == 3 or gT == 6:
349+
gTypeListPoly = [ QGis.WKBPolygon, QGis.WKBMultiPolygon ]
350+
return gTypeListPoly
351+
elif gT == 2 or gT == 5:
352+
gTypeListLine = [ QGis.WKBLineString, QGis.WKBMultiLineString ]
353+
return gTypeListLine
354+
347355
def getShapesByGeometryType( baseDir, inShapes, geomType ):
348356
outShapes = QStringList()
349357
for fileName in inShapes:

0 commit comments

Comments
 (0)