Skip to content
This repository has been archived by the owner on Mar 6, 2024. It is now read-only.

Commit

Permalink
more error checks with invalid geometries.
Browse files Browse the repository at this point in the history
  • Loading branch information
wilhelmberg committed Mar 26, 2014
1 parent 51c0ef0 commit b51b651
Show file tree
Hide file tree
Showing 10 changed files with 140 additions and 69 deletions.
Binary file modified VoGisProfilTool/VoGisProfilTool.zip
Binary file not shown.
2 changes: 1 addition & 1 deletion VoGisProfilTool/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def description():


def version():
return "1.8.5"
return "1.8.7"


def icon():
Expand Down
2 changes: 1 addition & 1 deletion VoGisProfilTool/metadata.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ name=VoGIS-ProfilTool
qgisMinimumVersion=1.8
qgisMaximumVersion=2.99
description=Create profiles from DHMs using vector geometries or a digitized line.
version=1.8.6
version=1.8.7
author=BergWerk GIS
[email protected]

Expand Down
2 changes: 1 addition & 1 deletion VoGisProfilTool/resources_rc.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# Resource object code
#
# Created: Sa. M�r 22 22:07:45 2014
# Created: Mi. M�r 26 17:48:20 2014
# by: The Resource Compiler for PyQt (Qt v4.8.1)
#
# WARNING! All changes made in this file will be lost!
Expand Down
2 changes: 1 addition & 1 deletion VoGisProfilTool/ui/ui_vogisprofiltoolmain.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# Form implementation generated from reading ui file 'ui/ui_vogisprofiltoolmain.ui'
#
# Created: Sat Mar 22 22:07:44 2014
# Created: Wed Mar 26 17:48:20 2014
# by: PyQt4 UI code generator 4.9.1
#
# WARNING! All changes made in this file will be lost!
Expand Down
2 changes: 1 addition & 1 deletion VoGisProfilTool/ui/ui_vogisprofiltoolplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# Form implementation generated from reading ui file 'ui/ui_vogisprofiltoolplot.ui'
#
# Created: Sat Mar 22 22:07:45 2014
# Created: Wed Mar 26 17:48:20 2014
# by: PyQt4 UI code generator 4.9.1
#
# WARNING! All changes made in this file will be lost!
Expand Down
10 changes: 9 additions & 1 deletion VoGisProfilTool/util/createProfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,17 @@ def create(self):
for feat in features:
feats.append(feat)

#for feat in feats:
# if feat.isValid() is False:
# return []

ut = Util(self.iface)
feats = ut.prepareFeatures(self.settings, provider, feats)
feats, err_msg = ut.prepareFeatures(self.settings, provider, feats)

if not err_msg is None:
#QMessageBox.critical(self.iface.mainWindow(), "VoGIS-Profiltool", err_msg)
QMessageBox.critical(self.iface.mainWindow(), 'PREPARE ERROR', err_msg)
return []

for f in feats:
geom = f.geometry()
Expand Down
88 changes: 72 additions & 16 deletions VoGisProfilTool/util/u.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,29 +104,61 @@ def createQgPointFeature(self, vertex):
qgPnt.setGeometry(pnt)
return qgPnt

def prepareFeatures(self, settings, provider, origFeats):
def prepareFeatures(self, settings, provider, feats):
"""explode multipart features"""
"""merge lines with same direction and same start and end vertices"""

newFeats = None
err_msg = 'Vector input not valid!\nPlease check message log and\n"Check Geometry Validity Tool".'

if self.valid(feats) is False:
return None, "Original features:\n" + err_msg

if settings.linesExplode is True:
newFeats = self.__explodeMultiPartFeatures(provider, origFeats)
#self.__printAttribs(newFeats[0].attributeMap())
feats = self.__explodeMultiPartFeatures(provider, feats)
#self.__printAttribs(feats[0].attributeMap())
if self.valid(feats) is False:
return None, "Explode features:\n" + err_msg

if settings.linesMerge is True:
newFeats = self.__mergeFeaturesAny(newFeats)
#self.__printAttribs(newFeats[0].attributeMap())
if len(feats) > 500:
QgsMessageLog.logMessage('+500 features: merging not possible', 'VoGis')
else:
feats = self.__mergeFeaturesAny(feats)
#self.__printAttribs(feats[0].attributeMap())
if self.valid(feats) is False:
return None, "Merge features (any):\n" + err_msg
feats = self.__mergeFeaturesSimple(provider, feats)
#self.__printAttribs(feats[0].attributeMap())
if self.valid(feats) is False:
return None, "Merge features (simple):\n" + err_msg

return feats, None

def valid(self, feats):
#QgsMessageLog.logMessage('check feat valid', 'VoGis')
err_cnt = 0
for feat in feats:
#QgsMessageLog.logMessage('feat', 'VoGis')
#if feat.isValid() is False:
# return [], "Vector input not valid!\nPlease check using the check validity tool."
#geom = QgsGeometry(feat.geometry())
geom = feat.geometry()
if geom.isGeosEmpty():
err_cnt +=1
QgsMessageLog.logMessage(u'$id [{0}] Empty geometry'.format(feat.id()), 'VoGis')
else:
errors = geom.validateGeometry()
if len(errors) > 0:
if len(errors) < 1:
continue
for err in errors:
err_cnt += 1
QgsMessageLog.logMessage(u'$id [{0}] {1}'.format(feat.id(), err.what()), 'VoGis')
return (1 > err_cnt)

newFeats = self.__mergeFeaturesSimple(provider, newFeats)
#self.__printAttribs(newFeats[0].attributeMap())
def __mergeFeaturesAny(self, origFeats):

if newFeats is None:
return origFeats
else:
return newFeats

def __mergeFeaturesAny(self, origFeats):
ll = LinkedList()
for idx, feat in enumerate(origFeats):
n = Node(idx)
Expand All @@ -150,13 +182,25 @@ def __mergeFeaturesAny(self, origFeats):
for idx in orderedIds:
newFeats.append(origFeats[idx])

tmpFeats = []
for feat in newFeats:
if feat.geometry().isGeosEmpty() is True:
QgsMessageLog.logMessage('dropping empty geometry', 'VoGis')
continue
else:
tmpFeats.append(feat)
newFeats = tmpFeats

return newFeats

def __mergeFeaturesSimple(self, provider, origFeats):

newFeats = []
QgsMessageLog.logMessage('---- Merge Simple: {0} features'.format(len(origFeats)), 'VoGis')

if len(origFeats) < 1:
return []

prevToPnt = None
#newGeom = QgsGeometry()
newGeom = QgsGeometry().fromPolyline([])
Expand Down Expand Up @@ -204,6 +248,15 @@ def __mergeFeaturesSimple(self, provider, origFeats):
#newFeats.append(self.createQgLineFeature(newGeom.asPolyline()))
newFeats.append(featNew)

tmpFeats = []
for feat in newFeats:
if feat.geometry().isGeosEmpty() is True:
QgsMessageLog.logMessage('dropping empty geometry', 'VoGis')
continue
else:
tmpFeats.append(feat)
newFeats = tmpFeats

QgsMessageLog.logMessage('---- {0} features after Merge Simple'.format(len(newFeats)), 'VoGis')

#for idx, f in enumerate(newFeats):
Expand Down Expand Up @@ -264,9 +317,12 @@ def explodeMultiPartFeature(self, provider, feat):
parts = feat.geometry().asGeometryCollection()

newFeats = []
for i in range(len(parts)):
tmpFeat.setGeometry(parts[i])
newFeats.append(QgsFeature(tmpFeat))
for part in parts:
if part.isGeosEmpty() is False:
tmpFeat.setGeometry(part)
newFeat = QgsFeature(tmpFeat)
#if newFeat.isValid() is True:
newFeats.append(newFeat)

return newFeats

Expand Down
97 changes: 52 additions & 45 deletions VoGisProfilTool/vogisprofiltoolmaindialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
* *
***************************************************************************/
"""
import traceback
import unicodedata
from PyQt4.QtCore import *
from PyQt4.QtGui import *
Expand Down Expand Up @@ -88,61 +89,67 @@ def __init__(self, interface, settings):
self.drawnLine = None

def accept(self):
#QMessageBox.warning(self.iface.mainWindow(), "VoGIS-Profiltool", "ACCEPTED")
if self.settings.onlyHektoMode is True and self.settings.mapData.rasters.count() > 0:
self.settings.onlyHektoMode = False

if self.settings.onlyHektoMode is False:
if self.settings.mapData.rasters.count() < 1:
#QMessageBox.warning(self.iface.mainWindow(), "VoGIS-Profiltool", u"Keine Raster vorhanden. Zum Hektometrieren Dialog neu öffnen.")
#return
retVal = QMessageBox.warning(self.iface.mainWindow(),
"VoGIS-Profiltool",
QApplication.translate('code', 'Keine Rasterebene vorhanden oder sichtbar! Nur hektometrieren?', None, QApplication.UnicodeUTF8),
QMessageBox.Yes | QMessageBox.No,
QMessageBox.Yes)
if retVal == QMessageBox.No:
try:
#QMessageBox.warning(self.iface.mainWindow(), "VoGIS-Profiltool", "ACCEPTED")
if self.settings.onlyHektoMode is True and self.settings.mapData.rasters.count() > 0:
self.settings.onlyHektoMode = False

if self.settings.onlyHektoMode is False:
if self.settings.mapData.rasters.count() < 1:
#QMessageBox.warning(self.iface.mainWindow(), "VoGIS-Profiltool", u"Keine Raster vorhanden. Zum Hektometrieren Dialog neu öffnen.")
#return
retVal = QMessageBox.warning(self.iface.mainWindow(),
"VoGIS-Profiltool",
QApplication.translate('code', 'Keine Rasterebene vorhanden oder sichtbar! Nur hektometrieren?', None, QApplication.UnicodeUTF8),
QMessageBox.Yes | QMessageBox.No,
QMessageBox.Yes)
if retVal == QMessageBox.No:
return
else:
self.settings.onlyHektoMode = True
self.settings.createHekto = True

if self.__getSettingsFromGui() is False:
return

if self.settings.onlyHektoMode is False:
if len(self.settings.mapData.rasters.selectedRasters()) < 1:
#QMessageBox.warning(self.iface.mainWindow(), "VoGIS-Profiltool", "Kein Raster selektiert!")
#msg =
#QMessageBox.warning(self.iface.mainWindow(), "VoGIS-Profiltool", msg)
QMessageBox.warning(self.iface.mainWindow(), "VoGIS-Profiltool", QApplication.translate('code', 'Kein Raster selektiert!', None, QApplication.UnicodeUTF8))
return
else:
self.settings.onlyHektoMode = True
self.settings.createHekto = True

if self.__getSettingsFromGui() is False:
return
QgsMessageLog.logMessage('modeLine!=line: {0}'.format(self.settings.modeLine != enumModeLine.line), 'VoGis')
QgsMessageLog.logMessage('customLine is None: {0}'.format(self.settings.mapData.customLine is None), 'VoGis')

if self.settings.onlyHektoMode is False:
if len(self.settings.mapData.rasters.selectedRasters()) < 1:
#QMessageBox.warning(self.iface.mainWindow(), "VoGIS-Profiltool", "Kein Raster selektiert!")
#msg =
#QMessageBox.warning(self.iface.mainWindow(), "VoGIS-Profiltool", msg)
QMessageBox.warning(self.iface.mainWindow(), "VoGIS-Profiltool", QApplication.translate('code', 'Kein Raster selektiert!', None, QApplication.UnicodeUTF8))
if self.settings.modeLine != enumModeLine.line and self.settings.mapData.customLine is None:
QMessageBox.warning(self.iface.mainWindow(), "VoGIS-Profiltool", QApplication.translate('code', 'Keine Profillinie vorhanden!', None, QApplication.UnicodeUTF8))
return

QgsMessageLog.logMessage('modeLine!=line: {0}'.format(self.settings.modeLine != enumModeLine.line), 'VoGis')
QgsMessageLog.logMessage('customLine is None: {0}'.format(self.settings.mapData.customLine is None), 'VoGis')

if self.settings.modeLine != enumModeLine.line and self.settings.mapData.customLine is None:
QMessageBox.warning(self.iface.mainWindow(), "VoGIS-Profiltool", QApplication.translate('code', 'Keine Profillinie vorhanden!', None, QApplication.UnicodeUTF8))
return
#self.rubberband.reset(self.polygon)
#QDialog.accept(self)

#self.rubberband.reset(self.polygon)
#QDialog.accept(self)
QApplication.setOverrideCursor(Qt.WaitCursor)

QApplication.setOverrideCursor(Qt.WaitCursor)
createProf = CreateProfile(self.iface, self.settings)
profiles = createProf.create()
QgsMessageLog.logMessage('ProfCnt: ' + str(len(profiles)), 'VoGis')

createProf = CreateProfile(self.iface, self.settings)
profiles = createProf.create()
QgsMessageLog.logMessage('ProfCnt: ' + str(len(profiles)), 'VoGis')
if len(profiles) < 1:
QApplication.restoreOverrideCursor()
QMessageBox.warning(self.iface.mainWindow(), "VoGIS-Profiltool", QApplication.translate('code', 'Es konnten keine Profile erstellt werden.', None, QApplication.UnicodeUTF8))
return

if len(profiles) < 1:
dlg = VoGISProfilToolPlotDialog(self.iface, self.settings, profiles)
dlg.show()
#result = self.dlg.exec_()
dlg.exec_()
except:
QApplication.restoreOverrideCursor()
QMessageBox.warning(self.iface.mainWindow(), "VoGIS-Profiltool", QApplication.translate('code', 'Es konnten keine Profile erstellt werden.', None, QApplication.UnicodeUTF8))
return

dlg = VoGISProfilToolPlotDialog(self.iface, self.settings, profiles)
dlg.show()
#result = self.dlg.exec_()
dlg.exec_()
ex = u'{0}'.format(traceback.format_exc())
msg = 'Unexpected ERROR:\n\n{0}'.format(ex[:2000])
QMessageBox.critical(self.iface.mainWindow(), "VoGIS-Profiltool", msg)

def reject(self):
#QMessageBox.warning(self.iface.mainWindow(), "VoGIS-Profiltool", "REJECTED")
Expand Down
4 changes: 2 additions & 2 deletions plugins.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version = '1.0' encoding = 'UTF-8'?>
<plugins>
<pyqgis_plugin name="VoGIS-ProfilTool" version="1.8.6">
<pyqgis_plugin name="VoGIS-ProfilTool" version="1.8.7">
<description><![CDATA[Create profiles from DHMs using vector geometries or a digitized line.]]></description>
<version>1.8.6</version>
<version>1.8.7</version>
<qgis_minimum_version>1.8.0</qgis_minimum_version>
<qgis_maximum_version>2.99.0</qgis_maximum_version>
<homepage>https://github.com/BergWerkGIS/VoGIS-Profil-Tool/</homepage>
Expand Down

0 comments on commit b51b651

Please sign in to comment.