Skip to content

Commit c1e1b28

Browse files
committedJul 11, 2016
[processing] Difference: don't ignore invalid geometries by default
Fix #9297
1 parent 1a7a87b commit c1e1b28

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed
 

‎python/plugins/processing/algs/qgis/Difference.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
from processing.core.ProcessingLog import ProcessingLog
3030
from processing.core.GeoAlgorithm import GeoAlgorithm
3131
from processing.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
32-
from processing.core.parameters import ParameterVector
32+
from processing.core.parameters import ParameterVector, ParameterBoolean
3333
from processing.core.outputs import OutputVector
3434
from processing.tools import dataobjects, vector
3535

@@ -38,6 +38,7 @@ class Difference(GeoAlgorithm):
3838

3939
INPUT = 'INPUT'
4040
OVERLAY = 'OVERLAY'
41+
IGNORE_INVALID = 'IGNORE_INVALID'
4142
OUTPUT = 'OUTPUT'
4243

4344
#==========================================================================
@@ -52,13 +53,16 @@ def defineCharacteristics(self):
5253
self.tr('Input layer'), [ParameterVector.VECTOR_TYPE_ANY]))
5354
self.addParameter(ParameterVector(Difference.OVERLAY,
5455
self.tr('Difference layer'), [ParameterVector.VECTOR_TYPE_ANY]))
56+
self.addParameter(ParameterBoolean(Difference.IGNORE_INVALID,
57+
self.tr('Ignore invalid input features'), False, True))
5558
self.addOutput(OutputVector(Difference.OUTPUT, self.tr('Difference')))
5659

5760
def processAlgorithm(self, progress):
5861
layerA = dataobjects.getObjectFromUri(
5962
self.getParameterValue(Difference.INPUT))
6063
layerB = dataobjects.getObjectFromUri(
6164
self.getParameterValue(Difference.OVERLAY))
65+
ignoreInvalid = self.getParameterValue(Difference.IGNORE_INVALID)
6266

6367
geomType = layerA.dataProvider().geometryType()
6468
writer = self.getOutputFromName(
@@ -82,12 +86,16 @@ def processAlgorithm(self, progress):
8286
tmpGeom = QgsGeometry(inFeatB.geometry())
8387
if diff_geom.intersects(tmpGeom):
8488
diff_geom = QgsGeometry(diff_geom.difference(tmpGeom))
85-
if diff_geom.isGeosEmpty() or not diff_geom.isGeosValid():
86-
ProcessingLog.addToLog(ProcessingLog.LOG_ERROR,
87-
self.tr('GEOS geoprocessing error: One or '
88-
'more input features have invalid '
89-
'geometry.'))
90-
add = False
89+
if diff_geom.isGeosEmpty():
90+
ProcessingLog.addToLog(ProcessingLog.LOG_INFO,
91+
self.tr('Feature with NULL geometry found.'))
92+
if not diff_geom.isGeosValid():
93+
if ignoreInvalid:
94+
ProcessingLog.addToLog(ProcessingLog.LOG_ERROR,
95+
self.tr('GEOS geoprocessing error: One or more input features have invalid geometry.'))
96+
add = False
97+
else:
98+
raise GeoAlgorithmExecutionException(self.tr('Features with invalid geometries found. Please fix these errors or specify the "Ignore invalid input features" flag'))
9199
break
92100

93101
if add:

0 commit comments

Comments
 (0)
Please sign in to comment.