Skip to content

Commit b81604c

Browse files
m-kuhnrldhont
authored andcommitted
Followup 594fafe, Also fix processing
1 parent 4bcc531 commit b81604c

File tree

4 files changed

+55
-55
lines changed

4 files changed

+55
-55
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(int_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(int_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(int_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(int_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(int_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() == 0 or QgsWKBTypes.flatType(int_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
@@ -78,7 +78,7 @@ def processAlgorithm(self, progress):
7878
if geom.intersects(tmpGeom):
7979
atMapB = inFeatB.attributes()
8080
int_geom = QgsGeometry(geom.intersection(tmpGeom))
81-
if int_geom.wkbType() == QGis.WKBUnknown:
81+
if int_geom.wkbType() == QGis.WKBUnknown or QgsWKBTypes.flatType(int_geom.geometry().wkbType()) == QgsWKBTypes.GeometryCollection:
8282
int_com = geom.combine(tmpGeom)
8383
int_sym = geom.symDifference(tmpGeom)
8484
int_geom = QgsGeometry(int_com.difference(int_sym))

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

+32-32
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
@@ -49,9 +49,9 @@ def processAlgorithm(self, progress):
4949

5050
fields = vector.combineVectorFields(vlayerA, vlayerB)
5151
names = [field.name() for field in fields]
52-
ProcessingLog.addToLog(ProcessingLog.LOG_INFO, str(names))
52+
ProcessingLog.addToLog(ProcessingLog.LOG_INFO, unicode(names))
5353
writer = self.getOutputFromName(Union.OUTPUT).getVectorWriter(fields,
54-
vproviderA.geometryType(), vproviderA.crs())
54+
vproviderA.geometryType(), vproviderA.crs())
5555
inFeatA = QgsFeature()
5656
inFeatB = QgsFeature()
5757
outFeat = QgsFeature()
@@ -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() == 0 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:
@@ -112,29 +112,29 @@ def processAlgorithm(self, progress):
112112
attrs.extend(atMapB)
113113
outFeat.setAttributes(attrs)
114114
writer.addFeature(outFeat)
115-
except Exception, err:
115+
except Exception as err:
116116
raise GeoAlgorithmExecutionException(
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)
135-
except Exception, err:
136-
raise GeoAlgorithmExecutionException(
137-
self.tr('Feature exception while computing union'))
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)
135+
except Exception as err:
136+
raise GeoAlgorithmExecutionException(
137+
self.tr('Feature exception while computing union'))
138138

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

@@ -154,7 +154,7 @@ def processAlgorithm(self, progress):
154154
outFeat.setGeometry(geom)
155155
outFeat.setAttributes(atMap)
156156
writer.addFeature(outFeat)
157-
except Exception, err:
157+
except Exception as err:
158158
raise GeoAlgorithmExecutionException(
159159
self.tr('Feature exception while computing union'))
160160
else:
@@ -174,7 +174,7 @@ def processAlgorithm(self, progress):
174174
outFeat.setGeometry(diff_geom)
175175
outFeat.setAttributes(atMap)
176176
writer.addFeature(outFeat)
177-
except Exception, err:
177+
except Exception as err:
178178
raise GeoAlgorithmExecutionException(
179179
self.tr('Geometry exception while computing intersection'))
180180

@@ -183,24 +183,24 @@ def processAlgorithm(self, progress):
183183
outFeat.setGeometry(diff_geom)
184184
outFeat.setAttributes(atMap)
185185
writer.addFeature(outFeat)
186-
except Exception, err:
186+
except Exception as err:
187187
raise err
188188
FEATURE_EXCEPT = False
189189
nElement += 1
190190

191191
del writer
192192
if not GEOS_EXCEPT:
193193
ProcessingLog.addToLog(ProcessingLog.LOG_WARNING,
194-
self.tr('Geometry exception while computing intersection'))
194+
self.tr('Geometry exception while computing intersection'))
195195
if not FEATURE_EXCEPT:
196196
ProcessingLog.addToLog(ProcessingLog.LOG_WARNING,
197-
self.tr('Feature exception while computing intersection'))
197+
self.tr('Feature exception while computing intersection'))
198198

199199
def defineCharacteristics(self):
200-
self.name = 'Union'
201-
self.group = 'Vector overlay tools'
200+
self.name, self.i18n_name = self.trAlgorithm('Union')
201+
self.group, self.i18n_group = self.trAlgorithm('Vector overlay tools')
202202
self.addParameter(ParameterVector(Union.INPUT,
203-
self.tr('Input layer'), [ParameterVector.VECTOR_TYPE_ANY]))
203+
self.tr('Input layer'), [ParameterVector.VECTOR_TYPE_ANY]))
204204
self.addParameter(ParameterVector(Union.INPUT2,
205-
self.tr('Input layer 2'), [ParameterVector.VECTOR_TYPE_ANY]))
205+
self.tr('Input layer 2'), [ParameterVector.VECTOR_TYPE_ANY]))
206206
self.addOutput(OutputVector(Union.OUTPUT, self.tr('Union')))

0 commit comments

Comments
 (0)