Skip to content

Commit

Permalink
[processing] Difference: don't ignore invalid geometries by default
Browse files Browse the repository at this point in the history
Fix #9297
  • Loading branch information
m-kuhn committed Jul 3, 2016
1 parent dd715b2 commit 143cfab
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions python/plugins/processing/algs/qgis/Difference.py
Expand Up @@ -33,7 +33,7 @@
from processing.core.ProcessingLog import ProcessingLog from processing.core.ProcessingLog import ProcessingLog
from processing.core.GeoAlgorithm import GeoAlgorithm from processing.core.GeoAlgorithm import GeoAlgorithm
from processing.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException 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.core.outputs import OutputVector
from processing.tools import dataobjects, vector from processing.tools import dataobjects, vector


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


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


def getIcon(self): def getIcon(self):
Expand All @@ -56,13 +57,16 @@ def defineCharacteristics(self):
self.tr('Input layer'), [ParameterVector.VECTOR_TYPE_ANY])) self.tr('Input layer'), [ParameterVector.VECTOR_TYPE_ANY]))
self.addParameter(ParameterVector(Difference.OVERLAY, self.addParameter(ParameterVector(Difference.OVERLAY,
self.tr('Difference layer'), [ParameterVector.VECTOR_TYPE_ANY])) 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'))) self.addOutput(OutputVector(Difference.OUTPUT, self.tr('Difference')))


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


geomType = layerA.dataProvider().geometryType() geomType = layerA.dataProvider().geometryType()
writer = self.getOutputFromName( writer = self.getOutputFromName(
Expand All @@ -86,12 +90,16 @@ def processAlgorithm(self, progress):
tmpGeom = QgsGeometry(inFeatB.geometry()) tmpGeom = QgsGeometry(inFeatB.geometry())
if diff_geom.intersects(tmpGeom): if diff_geom.intersects(tmpGeom):
diff_geom = QgsGeometry(diff_geom.difference(tmpGeom)) diff_geom = QgsGeometry(diff_geom.difference(tmpGeom))
if diff_geom.isGeosEmpty() or not diff_geom.isGeosValid(): if diff_geom.isGeosEmpty():
ProcessingLog.addToLog(ProcessingLog.LOG_ERROR, ProcessingLog.addToLog(ProcessingLog.LOG_INFO,
self.tr('GEOS geoprocessing error: One or ' self.tr('Feature with NULL geometry found.'))
'more input features have invalid ' if not diff_geom.isGeosValid():
'geometry.')) if ignoreInvalid:
add = False 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 break


if add: if add:
Expand Down

0 comments on commit 143cfab

Please sign in to comment.