Skip to content

Commit

Permalink
send log messages in case of invalid geometry
Browse files Browse the repository at this point in the history
  • Loading branch information
zsiki committed Jun 17, 2015
1 parent d1884af commit 3b210f4
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions realcentroid.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,15 @@ def centroids(self):
features = vlayer.selectedFeatures()
else:
features = vlayer.getFeatures()
nElement = 0
nError = 0
for inFeat in features:
#nElement += 1
nElement += 1
inGeom = inFeat.geometry()
if inGeom is None or inGeom.isGeosEmpty() or not inGeom.isGeosValid():

QgsMessageLog.logMessage("Feature %d skipped (empty or invalid geometry)" % nElement, 'realcentroid')
nError += 1
continue
if inGeom.isMultipart():
# find largest part in case of multipart
Expand Down Expand Up @@ -112,6 +117,8 @@ def centroids(self):
line = horiz.intersection(inGeom)
if line is None:
# skip invalid geometry
QgsMessageLog.logMessage("Feature %d skipped (empty or invalid geometry)" % nElement, 'realcentroid')
nError += 1
continue
elif line.isMultipart():
# find longest intersection
Expand All @@ -133,11 +140,15 @@ def centroids(self):
del writer
# add centroid shape to canvas
if self.dlg.ui.addBox.checkState() == Qt.Checked:
if not util.addShape(self.dlg.shapefileName):
QMessageBox.warning(self, "RealCentroid", \
QApplication.translate("RealCentroid", \
if not util.addShape(self.dlg.shapefileName):
QMessageBox.warning(None, "RealCentroid", \
QApplication.translate("RealCentroid", \
"Error loading shapefile:\n", None, \
QApplication.UnicodeUTF8) + self.dlg.shapefileName)
if nError > 0:
QMessageBox.warning(None, "RealCentroid", \
QApplication.translate("RealCentroid", \
"Invalid or empty geometries found, see log messages"))

# run method that performs all the real work
def run(self):
Expand Down

0 comments on commit 3b210f4

Please sign in to comment.