Skip to content

Commit 6910a2e

Browse files
committed
[processing] fix fTools Clip algorithm (fix #7281)
1 parent f7aab64 commit 6910a2e

File tree

1 file changed

+31
-19
lines changed
  • python/plugins/processing/algs/ftools

1 file changed

+31
-19
lines changed

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

+31-19
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,15 @@
2626
from PyQt4.QtCore import *
2727
from qgis.core import *
2828
from processing.core.GeoAlgorithm import GeoAlgorithm
29-
from processing.tools import dataobjects, vector
3029
from processing.core.ProcessingLog import ProcessingLog
3130
from processing.parameters.ParameterVector import ParameterVector
3231
from processing.outputs.OutputVector import OutputVector
32+
from processing.tools import dataobjects, vector
3333
from processing.tools import vector as utils
3434

3535
class Clip(GeoAlgorithm):
3636

37+
3738
INPUT = "INPUT"
3839
OVERLAY = "OVERLAY"
3940
OUTPUT = "OUTPUT"
@@ -66,33 +67,44 @@ def processAlgorithm(self, progress):
6667
for inFeatA in selectionA:
6768
geom = QgsGeometry(inFeatA.geometry())
6869
attrs = inFeatA.attributes()
69-
intersections = index.intersects(geom.boundingBox())
70+
intersects = index.intersects(geom.boundingBox())
7071
first = True
7172
found = False
72-
if len(intersections) > 0:
73-
for i in intersections:
74-
request = QgsFeatureRequest().setFilterFid(i)
75-
inFeatB = layerB.getFeatures(request).next()
73+
if len(intersects) > 0:
74+
for i in intersects:
75+
layerB.getFeatures(QgsFeatureRequest().setFilterFid(i)).nextFeature(inFeatB)
7676
tmpGeom = QgsGeometry(inFeatB.geometry())
7777
if tmpGeom.intersects(geom):
7878
found = True
7979
if first:
8080
outFeat.setGeometry(QgsGeometry(tmpGeom))
8181
first = False
8282
else:
83-
cur_geom = QgsGeometry(outFeat.geometry())
84-
new_geom = QgsGeometry(cur_geom.combine(tmpGeom))
85-
outFeat.setGeometry(QgsGeometry(new_geom))
86-
if found:
87-
cur_geom = QgsGeometry(outFeat.geometry())
88-
new_geom = QgsGeometry(geom.intersection(cur_geom))
89-
if new_geom.wkbType() == QGis.WKBNoGeometry :
90-
int_com = QgsGeometry(geom.combine(cur_geom))
91-
int_sym = QgsGeometry(geom.symDifference(cur_geom))
92-
new_geom = QgsGeometry(int_com.difference(int_sym))
93-
outFeat.setGeometry(new_geom)
94-
outFeat.setAttributes(attrs)
95-
writer.addFeature(outFeat)
83+
try:
84+
cur_geom = QgsGeometry(outFeat.geometry())
85+
new_geom = QgsGeometry(cur_geom.combine(tmpGeom))
86+
outFeat.setGeometry(QgsGeometry(new_geom))
87+
except:
88+
ProcessingLog.addToLog(ProcessingLog.LOG_ERROR, "GEOS geoprocessing error: One or more input features have invalid geometry.")
89+
break
90+
if found:
91+
try:
92+
cur_geom = QgsGeometry(outFeat.geometry())
93+
new_geom = QgsGeometry(geom.intersection(cur_geom))
94+
if new_geom.wkbType() == 0:
95+
int_com = QgsGeometry(geom.combine(cur_geom))
96+
int_sym = QgsGeometry(geom.symDifference(cur_geom))
97+
new_geom = QgsGeometry(int_com.difference(int_sym))
98+
try:
99+
outFeat.setGeometry(new_geom)
100+
outFeat.setAttributes(attrs)
101+
writer.addFeature(outFeat)
102+
except:
103+
ProcessingLog.addToLog(ProcessingLog.LOG_ERROR, "Feature geometry error: One or more output features ignored due to invalid geometry.")
104+
continue
105+
except:
106+
ProcessingLog.addToLog(ProcessingLog.LOG_ERROR, "GEOS geoprocessing error: One or more input features have invalid geometry.")
107+
continue
96108

97109
current += 1
98110
progress.setPercentage(int(current * total))

0 commit comments

Comments
 (0)