Skip to content

Commit

Permalink
[processing] skip invalid geometries when buffering (fix #13763)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbruy committed Jan 15, 2016
1 parent 0c02f18 commit 3bc3f52
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions python/plugins/processing/algs/qgis/Buffer.py
Expand Up @@ -26,6 +26,8 @@
__revision__ = '$Format:%H$'

from qgis.core import QgsFeature, QgsGeometry

from processing.core.ProcessingLog import ProcessingLog
from processing.tools import vector


Expand Down Expand Up @@ -55,6 +57,9 @@ def buffering(progress, writer, distance, field, useField, layer, dissolve,
value = distance

inGeom = QgsGeometry(inFeat.geometry())
if inGeom.isGeosEmpty() or not inGeom.isGeosValid():
ProcessingLog.addToLog('Feature {} has empty or invalid geometry. Skipping...'.format(inFeat.id()), ProcessingLog.LOG_WARNING)
continue
outGeom = inGeom.buffer(float(value), segments)
if first:
tempGeom = QgsGeometry(outGeom)
Expand All @@ -77,6 +82,10 @@ def buffering(progress, writer, distance, field, useField, layer, dissolve,
else:
value = distance
inGeom = QgsGeometry(inFeat.geometry())
if inGeom.isGeosEmpty() or not inGeom.isGeosValid():
ProcessingLog.addToLog('Feature {} has empty or invalid geometry. Skipping...'.format(inFeat.id()), ProcessingLog.LOG_WARNING)
continue

outGeom = inGeom.buffer(float(value), segments)
outFeat.setGeometry(outGeom)
outFeat.setAttributes(attrs)
Expand Down

3 comments on commit 3bc3f52

@m-kuhn
Copy link
Member

@m-kuhn m-kuhn commented on 3bc3f52 Jan 15, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just for your info (I don't think it applies here), QgsVectorFileWriter can now also produce geometry collections

@alexbruy
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Matthias! But as I understand such geometries still valid from GEOS point of view and should be correctly handled

@m-kuhn
Copy link
Member

@m-kuhn m-kuhn commented on 3bc3f52 Jan 15, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Absolutely, I think here you check the input geometries, this only applies where output geometries are dismissed because of a format incompatible with the produced output file.

It's not yet implemented anywhere in processing, just wanted to make you aware of it ;)

Please sign in to comment.