29
29
from processing .core .ProcessingLog import ProcessingLog
30
30
from processing .core .GeoAlgorithm import GeoAlgorithm
31
31
from processing .core .GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
32
- from processing .core .parameters import ParameterVector
32
+ from processing .core .parameters import ParameterVector , ParameterBoolean
33
33
from processing .core .outputs import OutputVector
34
34
from processing .tools import dataobjects , vector
35
35
@@ -38,6 +38,7 @@ class Difference(GeoAlgorithm):
38
38
39
39
INPUT = 'INPUT'
40
40
OVERLAY = 'OVERLAY'
41
+ IGNORE_INVALID = 'IGNORE_INVALID'
41
42
OUTPUT = 'OUTPUT'
42
43
43
44
#==========================================================================
@@ -52,13 +53,16 @@ def defineCharacteristics(self):
52
53
self .tr ('Input layer' ), [ParameterVector .VECTOR_TYPE_ANY ]))
53
54
self .addParameter (ParameterVector (Difference .OVERLAY ,
54
55
self .tr ('Difference layer' ), [ParameterVector .VECTOR_TYPE_ANY ]))
56
+ self .addParameter (ParameterBoolean (Difference .IGNORE_INVALID ,
57
+ self .tr ('Ignore invalid input features' ), False , True ))
55
58
self .addOutput (OutputVector (Difference .OUTPUT , self .tr ('Difference' )))
56
59
57
60
def processAlgorithm (self , progress ):
58
61
layerA = dataobjects .getObjectFromUri (
59
62
self .getParameterValue (Difference .INPUT ))
60
63
layerB = dataobjects .getObjectFromUri (
61
64
self .getParameterValue (Difference .OVERLAY ))
65
+ ignoreInvalid = self .getParameterValue (Difference .IGNORE_INVALID )
62
66
63
67
geomType = layerA .dataProvider ().geometryType ()
64
68
writer = self .getOutputFromName (
@@ -82,12 +86,16 @@ def processAlgorithm(self, progress):
82
86
tmpGeom = QgsGeometry (inFeatB .geometry ())
83
87
if diff_geom .intersects (tmpGeom ):
84
88
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' ))
91
99
break
92
100
93
101
if add :
0 commit comments