diff --git a/VoGisProfilTool/VoGisProfilTool.zip b/VoGisProfilTool/VoGisProfilTool.zip index daabc89..f83337b 100644 Binary files a/VoGisProfilTool/VoGisProfilTool.zip and b/VoGisProfilTool/VoGisProfilTool.zip differ diff --git a/VoGisProfilTool/__init__.py b/VoGisProfilTool/__init__.py index 2b4f153..aa9d877 100644 --- a/VoGisProfilTool/__init__.py +++ b/VoGisProfilTool/__init__.py @@ -31,7 +31,7 @@ def description(): def version(): - return "1.8.5" + return "1.8.7" def icon(): diff --git a/VoGisProfilTool/metadata.txt b/VoGisProfilTool/metadata.txt index c2dbf3d..6e24b5e 100644 --- a/VoGisProfilTool/metadata.txt +++ b/VoGisProfilTool/metadata.txt @@ -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=wb@BergWerk-GIS.at diff --git a/VoGisProfilTool/resources_rc.py b/VoGisProfilTool/resources_rc.py index c38da45..cd81def 100644 --- a/VoGisProfilTool/resources_rc.py +++ b/VoGisProfilTool/resources_rc.py @@ -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! diff --git a/VoGisProfilTool/ui/ui_vogisprofiltoolmain.py b/VoGisProfilTool/ui/ui_vogisprofiltoolmain.py index 833cf18..a0314ac 100644 --- a/VoGisProfilTool/ui/ui_vogisprofiltoolmain.py +++ b/VoGisProfilTool/ui/ui_vogisprofiltoolmain.py @@ -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! diff --git a/VoGisProfilTool/ui/ui_vogisprofiltoolplot.py b/VoGisProfilTool/ui/ui_vogisprofiltoolplot.py index c28fff1..3fafebd 100644 --- a/VoGisProfilTool/ui/ui_vogisprofiltoolplot.py +++ b/VoGisProfilTool/ui/ui_vogisprofiltoolplot.py @@ -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! diff --git a/VoGisProfilTool/util/createProfile.py b/VoGisProfilTool/util/createProfile.py index 8a9c6b7..e957c8a 100644 --- a/VoGisProfilTool/util/createProfile.py +++ b/VoGisProfilTool/util/createProfile.py @@ -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() diff --git a/VoGisProfilTool/util/u.py b/VoGisProfilTool/util/u.py index 7731532..f7648df 100644 --- a/VoGisProfilTool/util/u.py +++ b/VoGisProfilTool/util/u.py @@ -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) @@ -150,6 +182,15 @@ 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): @@ -157,6 +198,9 @@ 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([]) @@ -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): @@ -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 diff --git a/VoGisProfilTool/vogisprofiltoolmaindialog.py b/VoGisProfilTool/vogisprofiltoolmaindialog.py index 0f783bf..8d8b064 100644 --- a/VoGisProfilTool/vogisprofiltoolmaindialog.py +++ b/VoGisProfilTool/vogisprofiltoolmaindialog.py @@ -19,6 +19,7 @@ * * ***************************************************************************/ """ +import traceback import unicodedata from PyQt4.QtCore import * from PyQt4.QtGui import * @@ -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") diff --git a/plugins.xml b/plugins.xml index 6da51b4..f99f12b 100644 --- a/plugins.xml +++ b/plugins.xml @@ -1,8 +1,8 @@ - + - 1.8.6 + 1.8.7 1.8.0 2.99.0 https://github.com/BergWerkGIS/VoGIS-Profil-Tool/