@@ -156,13 +156,7 @@ def manageGui( self ):
156
156
self .inShapeA .clear ()
157
157
self .inShapeB .clear ()
158
158
159
- if self .myFunction == 5 or self .myFunction == 8 or self .myFunction == 3 :
160
- myListA = ftools_utils .getLayerNames ( [ QGis .Point , QGis .Line , QGis .Polygon ] )
161
- myListB = ftools_utils .getLayerNames ( [ QGis .Polygon ] )
162
- elif self .myFunction == 7 or self .myFunction == 6 :
163
- myListA = ftools_utils .getLayerNames ( [ QGis .Point , QGis .Line , QGis .Polygon ] ) # added points and lines to test
164
- myListB = ftools_utils .getLayerNames ( [ QGis .Point , QGis .Line , QGis .Polygon ] ) # added points and lines to test
165
- elif self .myFunction == 4 :
159
+ if self .myFunction == 4 :
166
160
myListA = ftools_utils .getLayerNames ( [ QGis .Polygon ] )
167
161
myListB = []
168
162
else :
@@ -1053,100 +1047,132 @@ def union( self ):
1053
1047
self .emit ( SIGNAL ( "runStatus(PyQt_PyObject)" ), 0 )
1054
1048
self .emit ( SIGNAL ( "runRange(PyQt_PyObject)" ), ( 0 , nFeat ) )
1055
1049
vproviderA .rewind ()
1050
+ count = 0
1056
1051
while vproviderA .nextFeature ( inFeatA ):
1057
1052
self .emit ( SIGNAL ( "runStatus(PyQt_PyObject)" ), nElement )
1058
1053
nElement += 1
1059
1054
found = False
1060
1055
geom = QgsGeometry ( inFeatA .geometry () )
1061
- diffGeom = QgsGeometry ( inFeatA . geometry () )
1056
+ diff_geom = QgsGeometry ( geom )
1062
1057
atMapA = inFeatA .attributeMap ()
1063
1058
intersects = indexA .intersects ( geom .boundingBox () )
1064
- if len ( intersects ) <= 0 :
1059
+ if len ( intersects ) < 1 :
1065
1060
try :
1066
1061
outFeat .setGeometry ( geom )
1067
1062
outFeat .setAttributeMap ( atMapA )
1068
1063
writer .addFeature ( outFeat )
1069
1064
except :
1070
1065
FEATURE_EXCEPT = False
1071
- continue
1066
+ # this really shouldn't happen, as we
1067
+ # haven't edited the input geom at all
1068
+ # continue
1072
1069
else :
1073
1070
for id in intersects :
1071
+ count += 1
1074
1072
vproviderB .featureAtId ( int ( id ), inFeatB , True , allAttrsB )
1075
1073
atMapB = inFeatB .attributeMap ()
1076
1074
tmpGeom = QgsGeometry ( inFeatB .geometry () )
1077
1075
try :
1078
1076
if geom .intersects ( tmpGeom ):
1079
1077
found = True
1080
- diff_geom = QgsGeometry ( geom .difference ( tmpGeom ) )
1081
- int_geom = QgsGeometry ( geom .intersection ( tmpGeom ) )
1082
- if int_geom .wkbType () == 7 :
1083
- int_com = geom .combine ( tmpGeom )
1084
- int_sym = geom .symDifference ( tmpGeom )
1085
- int_geom = QgsGeometry ( int_com .difference ( int_sym ) )
1078
+ int_geom = geom .intersection ( tmpGeom )
1079
+ if int_geom is None :
1080
+ GEOS_EXCEPT = False
1081
+ # There was a problem creating the intersection
1082
+ int_geom = QgsGeometry ()
1083
+ else :
1084
+ int_geom = QgsGeometry (int_geom )
1085
+ if diff_geom .intersects ( tmpGeom ):
1086
+ diff_geom = diff_geom .difference ( tmpGeom )
1087
+ if diff_geom is None :
1088
+ # It's possible there was an error here?
1089
+ diff_geom = QgsGeometry ()
1090
+ else :
1091
+ diff_geom = QgsGeometry (diff_geom )
1092
+ if int_geom .wkbType () == 0 :
1093
+ # intersection produced different geomety types
1094
+ temp_list = int_geom .asGeometryCollection ()
1095
+ for i in temp_list :
1096
+ if i .type () == geom .type ():
1097
+ int_geom = QgsGeometry ( i )
1086
1098
try :
1087
1099
outFeat .setGeometry ( int_geom )
1088
1100
outFeat .setAttributeMap ( ftools_utils .combineVectorAttributes ( atMapA , atMapB ) )
1101
+ # print int_geom.wkbType()
1089
1102
writer .addFeature ( outFeat )
1090
- except :
1091
- FEATURE_EXCEPT = False
1092
- continue
1093
- else :
1094
- try :
1095
- outFeat .setGeometry ( geom )
1096
- outFeat .setAttributeMap ( atMapA )
1097
- writer .addFeature ( outFeat )
1098
- except :
1103
+ except Exception , err :
1104
+ # print str(err)
1099
1105
FEATURE_EXCEPT = False
1100
- continue
1101
- except :
1106
+ # else:
1107
+ # # this only happends if the bounding box
1108
+ # # intersects, but the geometry doesn't
1109
+ # try:
1110
+ # outFeat.setGeometry( geom )
1111
+ # outFeat.setAttributeMap( atMapA )
1112
+ # print geom.wkbType()
1113
+ # writer.addFeature( outFeat )
1114
+ # except:
1115
+ ## # also shoudn't ever happen
1116
+ # FEATURE_EXCEPT = False
1117
+ # pass
1118
+ except Exception , err :
1119
+ # print str(err)
1102
1120
GEOS_EXCEPT = False
1103
1121
found = False
1104
- continue
1105
1122
if found :
1106
1123
try :
1124
+ if diff_geom .wkbType () == 0 :
1125
+ temp_list = diff_geom .asGeometryCollection ()
1126
+ for i in temp_list :
1127
+ if i .type () == geom .type ():
1128
+ diff_geom = QgsGeometry ( i )
1107
1129
outFeat .setGeometry ( diff_geom )
1108
1130
outFeat .setAttributeMap ( atMapA )
1131
+ # print diff_geom.wkbType()
1109
1132
writer .addFeature ( outFeat )
1110
- except :
1133
+ except Exception , err :
1134
+ # print str(err)
1111
1135
FEATURE_EXCEPT = False
1112
- continue
1136
+ # continue
1113
1137
length = len ( vproviderA .fields ().values () )
1114
1138
vproviderB .rewind ()
1115
1139
while vproviderB .nextFeature ( inFeatA ):
1116
- add = True
1140
+ add = False
1117
1141
geom = QgsGeometry ( inFeatA .geometry () )
1118
1142
diff_geom = QgsGeometry ( geom )
1119
1143
atMap = inFeatA .attributeMap ().values ()
1120
1144
atMap = dict ( zip ( range ( length , length + len ( atMap ) ), atMap ) )
1121
1145
intersects = indexB .intersects ( geom .boundingBox () )
1122
- if len (intersects ) <= 0 :
1146
+ if len (intersects ) < 1 :
1123
1147
try :
1124
- outFeat .setGeometry ( diff_geom )
1148
+ outFeat .setGeometry ( geom )
1125
1149
outFeat .setAttributeMap ( atMap )
1126
1150
writer .addFeature ( outFeat )
1127
- except :
1151
+ except Exception , err :
1152
+ # print str(err)
1128
1153
FEATURE_EXCEPT = False
1129
- continue
1130
1154
else :
1131
1155
for id in intersects :
1132
1156
vproviderA .featureAtId ( int ( id ), inFeatB , True , allAttrsA )
1133
1157
atMapB = inFeatB .attributeMap ()
1134
1158
tmpGeom = QgsGeometry ( inFeatB .geometry () )
1135
1159
try :
1136
1160
if diff_geom .intersects ( tmpGeom ):
1161
+ add = True
1137
1162
diff_geom = QgsGeometry ( diff_geom .difference ( tmpGeom ) )
1138
- except :
1163
+ except Exception , err :
1164
+ # print str(err)
1139
1165
add = False
1140
1166
GEOS_EXCEPT = False
1141
- break
1142
1167
if add :
1143
1168
try :
1144
1169
outFeat .setGeometry ( diff_geom )
1145
- outFeat .setAttributeMap ( atMap )
1170
+ outFeat .setAttributeMap ( atMapB )
1146
1171
writer .addFeature ( outFeat )
1147
- except :
1172
+ except Exception , err :
1173
+ # print str(err)
1148
1174
FEATURE_EXCEPT = False
1149
- continue
1175
+ # continue
1150
1176
self .emit ( SIGNAL ( "runStatus(PyQt_PyObject)" ), nElement )
1151
1177
nElement += 1
1152
1178
del writer
0 commit comments