Skip to content

Commit 62591d9

Browse files
committed
Followup 436c30f, Also fix processing
And some code fixes
1 parent 436c30f commit 62591d9

File tree

4 files changed

+42
-42
lines changed

4 files changed

+42
-42
lines changed

python/plugins/fTools/tools/doGeoprocessing.py

+19-19
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232

3333
from PyQt4.QtCore import SIGNAL, QObject, Qt, QFile, QThread, QVariant
3434
from PyQt4.QtGui import QDialog, QDoubleValidator, QDialogButtonBox, QMessageBox
35-
from qgis.core import QGis, QgsVectorFileWriter, QgsFeature, QgsGeometry, QgsFields, QgsField, QgsFeatureRequest, QgsPoint, QgsDistanceArea, QgsMessageLog, QgsWKBTypes
35+
from qgis.core import QGis, QgsVectorFileWriter, QgsFeature, QgsGeometry, QgsFields, QgsField, QgsFeatureRequest, QgsPoint, QgsDistanceArea, QgsWKBTypes
3636

3737
from ui_frmGeoprocessing import Ui_Dialog
3838
import ftools_utils
@@ -204,14 +204,14 @@ def populateLayers(self):
204204
self.inShapeA.addItems(myListA)
205205
self.inShapeB.addItems(myListB)
206206

207-
#1: Buffer
208-
#2: Convex Hull
209-
#3: Difference
210-
#4: Dissolve
211-
#5: Intersection
212-
#6: Union
213-
#7: Symmetrical Difference
214-
#8: Clip
207+
# 1: Buffer
208+
# 2: Convex Hull
209+
# 3: Difference
210+
# 4: Dissolve
211+
# 5: Intersection
212+
# 6: Union
213+
# 7: Symmetrical Difference
214+
# 8: Clip
215215

216216
def geoprocessing(self, myLayerA, myLayerB, myParam, myMerge, mySelectionA, mySelectionB, mySegments):
217217
check = QFile(self.shapefileName)
@@ -966,7 +966,7 @@ def intersect(self):
966966
if geom.intersects(tmpGeom):
967967
atMapB = inFeatB.attributes()
968968
int_geom = QgsGeometry(geom.intersection(tmpGeom))
969-
if int_geom.wkbType() == 0 or QgsWKBTypes.flatType( int_geom.geometry().wkbType() ) == QgsWKBTypes.GeometryCollection:
969+
if int_geom.wkbType() == QGis.WKBUnknown or QgsWKBTypes.flatType(int_geom.geometry().wkbType()) == QgsWKBTypes.GeometryCollection:
970970
int_com = geom.combine(tmpGeom)
971971
int_sym = geom.symDifference(tmpGeom)
972972
int_geom = QgsGeometry(int_com.difference(int_sym))
@@ -1001,7 +1001,7 @@ def intersect(self):
10011001
if geom.intersects(tmpGeom):
10021002
atMapB = inFeatB.attributes()
10031003
int_geom = QgsGeometry(geom.intersection(tmpGeom))
1004-
if int_geom.wkbType() == 0 or QgsWKBTypes.flatType( int_geom.geometry().wkbType() ) == QgsWKBTypes.GeometryCollection:
1004+
if int_geom.wkbType() == QGis.WKBUnknown or QgsWKBTypes.flatType(int_geom.geometry().wkbType()) == QgsWKBTypes.GeometryCollection:
10051005
int_com = geom.combine(tmpGeom)
10061006
int_sym = geom.symDifference(tmpGeom)
10071007
int_geom = QgsGeometry(int_com.difference(int_sym))
@@ -1040,7 +1040,7 @@ def intersect(self):
10401040
if geom.intersects(tmpGeom):
10411041
atMapB = inFeatB.attributes()
10421042
int_geom = QgsGeometry(geom.intersection(tmpGeom))
1043-
if int_geom.wkbType() == 0 or QgsWKBTypes.flatType( int_geom.geometry().wkbType() ) == QgsWKBTypes.GeometryCollection:
1043+
if int_geom.wkbType() == QGis.WKBUnknown or QgsWKBTypes.flatType(int_geom.geometry().wkbType()) == QgsWKBTypes.GeometryCollection:
10441044
int_com = geom.combine(tmpGeom)
10451045
int_sym = geom.symDifference(tmpGeom)
10461046
int_geom = QgsGeometry(int_com.difference(int_sym))
@@ -1072,7 +1072,7 @@ def intersect(self):
10721072
if geom.intersects(tmpGeom):
10731073
atMapB = inFeatB.attributes()
10741074
int_geom = QgsGeometry(geom.intersection(tmpGeom))
1075-
if ( int_geom.wkbType() == 0 or QgsWKBTypes.flatType( int_geom.geometry().wkbType() ) == QgsWKBTypes.GeometryCollection ):
1075+
if (int_geom.wkbType() == QGis.WKBUnknown or QgsWKBTypes.flatType(int_geom.geometry().wkbType()) == QgsWKBTypes.GeometryCollection):
10761076
int_com = geom.combine(tmpGeom)
10771077
int_sym = geom.symDifference(tmpGeom)
10781078
int_geom = QgsGeometry(int_com.difference(int_sym))
@@ -1161,7 +1161,7 @@ def union(self):
11611161
else:
11621162
int_geom = QgsGeometry(int_geom)
11631163

1164-
if int_geom.wkbType() == 0 or QgsWKBTypes.flatType( int_geom.geometry().wkbType() ) == QgsWKBTypes.GeometryCollection:
1164+
if int_geom.wkbType() == QGis.WKBUnknown or QgsWKBTypes.flatType(int_geom.geometry().wkbType()) == QgsWKBTypes.GeometryCollection:
11651165
# intersection produced different geometry types
11661166
temp_list = int_geom.asGeometryCollection()
11671167
for i in temp_list:
@@ -1197,7 +1197,7 @@ def union(self):
11971197
intB = QgsGeometry.unaryUnion(lstIntersectingB)
11981198
diff_geom = diff_geom.difference(intB)
11991199

1200-
if diff_geom.wkbType() == 0 or QgsWKBTypes.flatType( int_geom.geometry().wkbType() ) == QgsWKBTypes.GeometryCollection:
1200+
if diff_geom.wkbType() == QGis.WKBUnknown or QgsWKBTypes.flatType(diff_geom.geometry().wkbType()) == QgsWKBTypes.GeometryCollection:
12011201
temp_list = diff_geom.asGeometryCollection()
12021202
for i in temp_list:
12031203
if i.type() == geom.type():
@@ -1415,7 +1415,7 @@ def clip(self):
14151415
try:
14161416
cur_geom = QgsGeometry(outFeat.geometry())
14171417
new_geom = QgsGeometry(geom.intersection(cur_geom))
1418-
if new_geom.wkbType() == 0 or QgsWKBTypes.flatType( int_geom.geometry().wkbType() ) == QgsWKBTypes.GeometryCollection:
1418+
if new_geom.wkbType() == QGis.WKBUnknown or QgsWKBTypes.flatType(new_geom.geometry().wkbType()) == QgsWKBTypes.GeometryCollection:
14191419
int_com = QgsGeometry(geom.combine(cur_geom))
14201420
int_sym = QgsGeometry(geom.symDifference(cur_geom))
14211421
new_geom = QgsGeometry(int_com.difference(int_sym))
@@ -1459,7 +1459,7 @@ def clip(self):
14591459
try:
14601460
cur_geom = QgsGeometry(outFeat.geometry())
14611461
new_geom = QgsGeometry(geom.intersection(cur_geom))
1462-
if new_geom.wkbType() == 0 or QgsWKBTypes.flatType( int_geom.geometry().wkbType() ) == QgsWKBTypes.GeometryCollection:
1462+
if new_geom.wkbType() == QGis.WKBUnknown or QgsWKBTypes.flatType(new_geom.geometry().wkbType()) == QgsWKBTypes.GeometryCollection:
14631463
int_com = QgsGeometry(geom.combine(cur_geom))
14641464
int_sym = QgsGeometry(geom.symDifference(cur_geom))
14651465
new_geom = QgsGeometry(int_com.difference(int_sym))
@@ -1511,7 +1511,7 @@ def clip(self):
15111511
try:
15121512
cur_geom = QgsGeometry(outFeat.geometry())
15131513
new_geom = QgsGeometry(geom.intersection(cur_geom))
1514-
if new_geom.wkbType() == 0 or QgsWKBTypes.flatType( int_geom.geometry().wkbType() ) == QgsWKBTypes.GeometryCollection:
1514+
if new_geom.wkbType() == QGis.WKBUnknown or QgsWKBTypes.flatType(new_geom.geometry().wkbType()) == QgsWKBTypes.GeometryCollection:
15151515
int_com = QgsGeometry(geom.combine(cur_geom))
15161516
int_sym = QgsGeometry(geom.symDifference(cur_geom))
15171517
new_geom = QgsGeometry(int_com.difference(int_sym))
@@ -1557,7 +1557,7 @@ def clip(self):
15571557
try:
15581558
cur_geom = QgsGeometry(outFeat.geometry())
15591559
new_geom = QgsGeometry(geom.intersection(cur_geom))
1560-
if new_geom.wkbType() == 0 or QgsWKBTypes.flatType( int_geom.geometry().wkbType() ) == QgsWKBTypes.GeometryCollection:
1560+
if new_geom.wkbType() == QGis.WKBUnknown or QgsWKBTypes.flatType(new_geom.geometry().wkbType()) == QgsWKBTypes.GeometryCollection:
15611561
int_com = QgsGeometry(geom.combine(cur_geom))
15621562
int_sym = QgsGeometry(geom.symDifference(cur_geom))
15631563
new_geom = QgsGeometry(int_com.difference(int_sym))

python/plugins/processing/algs/qgis/Clip.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
__revision__ = '$Format:%H$'
2727

28-
from qgis.core import QgsFeature, QgsGeometry, QgsFeatureRequest
28+
from qgis.core import QgsFeature, QgsGeometry, QgsFeatureRequest, QgsWKBTypes
2929
from processing.core.GeoAlgorithm import GeoAlgorithm
3030
from processing.core.ProcessingLog import ProcessingLog
3131
from processing.core.parameters import ParameterVector
@@ -103,7 +103,7 @@ def processAlgorithm(self, progress):
103103
try:
104104
cur_geom = QgsGeometry(outFeat.geometry())
105105
new_geom = QgsGeometry(geom.intersection(cur_geom))
106-
if new_geom.wkbType() == 0:
106+
if new_geom.wkbType() == QGis.WKBUnknown or QgsWKBTypes.flatType(new_geom.geometry().wkbType()) == QgsWKBTypes.GeometryCollection:
107107
int_com = QgsGeometry(geom.combine(cur_geom))
108108
int_sym = QgsGeometry(geom.symDifference(cur_geom))
109109
new_geom = QgsGeometry(int_com.difference(int_sym))

python/plugins/processing/algs/qgis/Intersection.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
__revision__ = '$Format:%H$'
2727

28-
from qgis.core import QGis, QgsFeatureRequest, QgsFeature, QgsGeometry
28+
from qgis.core import QGis, QgsFeatureRequest, QgsFeature, QgsGeometry, QgsWKBTypes
2929
from processing.core.GeoAlgorithm import GeoAlgorithm
3030
from processing.core.ProcessingLog import ProcessingLog
3131
from processing.core.parameters import ParameterVector
@@ -79,7 +79,7 @@ def processAlgorithm(self, progress):
7979
if geom.intersects(tmpGeom):
8080
atMapB = inFeatB.attributes()
8181
int_geom = QgsGeometry(geom.intersection(tmpGeom))
82-
if int_geom.wkbType() == QGis.WKBUnknown:
82+
if int_geom.wkbType() == QGis.WKBUnknown or QgsWKBTypes.flatType(int_geom.geometry().wkbType()) == QgsWKBTypes.GeometryCollection:
8383
int_com = geom.combine(tmpGeom)
8484
int_sym = geom.symDifference(tmpGeom)
8585
int_geom = QgsGeometry(int_com.difference(int_sym))

python/plugins/processing/algs/qgis/Union.py

+19-19
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
__revision__ = '$Format:%H$'
2727

28-
from qgis.core import QgsFeatureRequest, QgsFeature, QgsGeometry
28+
from qgis.core import QgsFeatureRequest, QgsFeature, QgsGeometry, QgsWKBTypes
2929
from processing.core.GeoAlgorithm import GeoAlgorithm
3030
from processing.core.ProcessingLog import ProcessingLog
3131
from processing.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
@@ -99,7 +99,7 @@ def processAlgorithm(self, progress):
9999
else:
100100
int_geom = QgsGeometry(int_geom)
101101

102-
if int_geom.wkbType() == 0:
102+
if int_geom.wkbType() == QGis.WKBUnknown or QgsWKBTypes.flatType(int_geom.geometry().wkbType()) == QgsWKBTypes.GeometryCollection:
103103
# Intersection produced different geomety types
104104
temp_list = int_geom.asGeometryCollection()
105105
for i in temp_list:
@@ -117,24 +117,24 @@ def processAlgorithm(self, progress):
117117
self.tr('Feature exception while computing union'))
118118

119119
try:
120-
# the remaining bit of inFeatA's geometry
121-
# if there is nothing left, this will just silently fail and we're good
122-
diff_geom = QgsGeometry(geom)
123-
if len(lstIntersectingB) != 0:
124-
intB = QgsGeometry.unaryUnion(lstIntersectingB)
125-
diff_geom = diff_geom.difference(intB)
126-
127-
if diff_geom.wkbType() == 0:
128-
temp_list = diff_geom.asGeometryCollection()
129-
for i in temp_list:
130-
if i.type() == geom.type():
131-
diff_geom = QgsGeometry(i)
132-
outFeat.setGeometry(diff_geom)
133-
outFeat.setAttributes(atMapA)
134-
writer.addFeature(outFeat)
120+
# the remaining bit of inFeatA's geometry
121+
# if there is nothing left, this will just silently fail and we're good
122+
diff_geom = QgsGeometry(geom)
123+
if len(lstIntersectingB) != 0:
124+
intB = QgsGeometry.unaryUnion(lstIntersectingB)
125+
diff_geom = diff_geom.difference(intB)
126+
127+
if diff_geom.wkbType() == 0 or QgsWKBTypes.flatType(int_geom.geometry().wkbType()) == QgsWKBTypes.GeometryCollection:
128+
temp_list = diff_geom.asGeometryCollection()
129+
for i in temp_list:
130+
if i.type() == geom.type():
131+
diff_geom = QgsGeometry(i)
132+
outFeat.setGeometry(diff_geom)
133+
outFeat.setAttributes(atMapA)
134+
writer.addFeature(outFeat)
135135
except Exception as err:
136-
raise GeoAlgorithmExecutionException(
137-
self.tr('Feature exception while computing union'))
136+
raise GeoAlgorithmExecutionException(
137+
self.tr('Feature exception while computing union'))
138138

139139
length = len(vproviderA.fields())
140140

0 commit comments

Comments
 (0)