Skip to content

Commit

Permalink
[processing] stop algorithm execution if geometry/feature error occured
Browse files Browse the repository at this point in the history
(fix #11986)
  • Loading branch information
alexbruy committed May 13, 2017
1 parent 3289d61 commit 7734d72
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions python/plugins/processing/algs/qgis/Intersection.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -95,10 +95,14 @@ def processAlgorithm(self, progress):
continue continue
else: else:
raise GeoAlgorithmExecutionException( raise GeoAlgorithmExecutionException(
self.tr('Input layer A contains NULL geometries. Please check "Ignore NULL geometries" if you want to run this algorithm anyway.')) self.tr('Input layer A contains NULL geometries. '
'Please check "Ignore NULL geometries" '
'if you want to run this algorithm anyway.'))
if not geom.isGeosValid(): if not geom.isGeosValid():
raise GeoAlgorithmExecutionException( raise GeoAlgorithmExecutionException(
self.tr('Input layer A contains invalid geometries (Feature {}). Unable to complete intersection algorithm.'.format(inFeatA.id()))) self.tr('Input layer A contains invalid geometries '
'(feature {}). Unable to complete intersection '
'algorithm.'.format(inFeatA.id())))
atMapA = inFeatA.attributes() atMapA = inFeatA.attributes()
intersects = index.intersects(geom.boundingBox()) intersects = index.intersects(geom.boundingBox())
for inFeatB in vlayerB.getFeatures(QgsFeatureRequest().setFilterFids(intersects)): for inFeatB in vlayerB.getFeatures(QgsFeatureRequest().setFilterFids(intersects)):
Expand All @@ -108,10 +112,14 @@ def processAlgorithm(self, progress):
continue continue
else: else:
raise GeoAlgorithmExecutionException( raise GeoAlgorithmExecutionException(
self.tr('Input layer B contains NULL geometries. Please check "Ignore NULL geometries" if you want to run this algorithm anyway.')) self.tr('Input layer B contains NULL geometries. '
'Please check "Ignore NULL geometries" '
'if you want to run this algorithm anyway.'))
if not geom.isGeosValid(): if not geom.isGeosValid():
raise GeoAlgorithmExecutionException( raise GeoAlgorithmExecutionException(
self.tr('Input layer B contains invalid geometries (Feature {}). Unable to complete intersection algorithm.'.format(inFeatB.id()))) self.tr('Input layer B contains invalid geometries '
'(feature {}). Unable to complete intersection '
'algorithm.'.format(inFeatB.id())))


if geom.intersects(tmpGeom): if geom.intersects(tmpGeom):
atMapB = inFeatB.attributes() atMapB = inFeatB.attributes()
Expand All @@ -126,10 +134,10 @@ def processAlgorithm(self, progress):
int_geom = QgsGeometry(diff_geom) int_geom = QgsGeometry(diff_geom)


if int_geom.isGeosEmpty() or not int_geom.isGeosValid(): if int_geom.isGeosEmpty() or not int_geom.isGeosValid():
ProcessingLog.addToLog(ProcessingLog.LOG_ERROR, raise GeoAlgorithmExecutionException(
self.tr('GEOS geoprocessing error: One or ' self.tr('GEOS geoprocessing error: One or '
'more input features have invalid ' 'more input features have invalid '
'geometry.')) 'geometry.'))
try: try:
if int_geom.wkbType() in wkbTypeGroups[wkbTypeGroups[int_geom.wkbType()]]: if int_geom.wkbType() in wkbTypeGroups[wkbTypeGroups[int_geom.wkbType()]]:
outFeat.setGeometry(int_geom) outFeat.setGeometry(int_geom)
Expand All @@ -139,8 +147,9 @@ def processAlgorithm(self, progress):
outFeat.setAttributes(attrs) outFeat.setAttributes(attrs)
writer.addFeature(outFeat) writer.addFeature(outFeat)
except: except:
ProcessingLog.addToLog(ProcessingLog.LOG_INFO, raise GeoAlgorithmExecutionException(
self.tr('Feature geometry error: One or more output features ignored due to invalid geometry.')) self.tr('Feature geometry error: one or '
continue 'more output features ignored due '
'to invalid geometry.'))


del writer del writer

0 comments on commit 7734d72

Please sign in to comment.