Skip to content
Permalink
Browse files

[processing] Difference: don't ignore invalid geometries by default

Fix #9297
  • Loading branch information
m-kuhn committed Jul 3, 2016
1 parent dd715b2 commit 143cfab1047f13db7654a4f241c1716d0d45c238
Showing with 15 additions and 7 deletions.
  1. +15 −7 python/plugins/processing/algs/qgis/Difference.py
@@ -33,7 +33,7 @@
from processing.core.ProcessingLog import ProcessingLog
from processing.core.GeoAlgorithm import GeoAlgorithm
from processing.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
from processing.core.parameters import ParameterVector
from processing.core.parameters import ParameterVector, ParameterBoolean
from processing.core.outputs import OutputVector
from processing.tools import dataobjects, vector

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

INPUT = 'INPUT'
OVERLAY = 'OVERLAY'
IGNORE_INVALID = 'IGNORE_INVALID'
OUTPUT = 'OUTPUT'

def getIcon(self):
@@ -56,13 +57,16 @@ def defineCharacteristics(self):
self.tr('Input layer'), [ParameterVector.VECTOR_TYPE_ANY]))
self.addParameter(ParameterVector(Difference.OVERLAY,
self.tr('Difference layer'), [ParameterVector.VECTOR_TYPE_ANY]))
self.addParameter(ParameterBoolean(Difference.IGNORE_INVALID,
self.tr('Ignore invalid input features'), False, True))
self.addOutput(OutputVector(Difference.OUTPUT, self.tr('Difference')))

def processAlgorithm(self, progress):
layerA = dataobjects.getObjectFromUri(
self.getParameterValue(Difference.INPUT))
layerB = dataobjects.getObjectFromUri(
self.getParameterValue(Difference.OVERLAY))
ignoreInvalid = self.getParameterValue(Difference.IGNORE_INVALID)

geomType = layerA.dataProvider().geometryType()
writer = self.getOutputFromName(
@@ -86,12 +90,16 @@ def processAlgorithm(self, progress):
tmpGeom = QgsGeometry(inFeatB.geometry())
if diff_geom.intersects(tmpGeom):
diff_geom = QgsGeometry(diff_geom.difference(tmpGeom))
if diff_geom.isGeosEmpty() or not diff_geom.isGeosValid():
ProcessingLog.addToLog(ProcessingLog.LOG_ERROR,
self.tr('GEOS geoprocessing error: One or '
'more input features have invalid '
'geometry.'))
add = False
if diff_geom.isGeosEmpty():
ProcessingLog.addToLog(ProcessingLog.LOG_INFO,
self.tr('Feature with NULL geometry found.'))
if not diff_geom.isGeosValid():
if ignoreInvalid:
ProcessingLog.addToLog(ProcessingLog.LOG_ERROR,
self.tr('GEOS geoprocessing error: One or more input features have invalid geometry.'))
add = False
else:
raise GeoAlgorithmExecutionException(self.tr('Features with invalid geometries found. Please fix these errors or specify the "Ignore invalid input features" flag'))
break

if add:

0 comments on commit 143cfab

Please sign in to comment.
You can’t perform that action at this time.