当前位置: 首页>>代码示例>>Python>>正文


Python QgsGeometryValidator.start方法代码示例

本文整理汇总了Python中qgis.core.QgsGeometryValidator.start方法的典型用法代码示例。如果您正苦于以下问题:Python QgsGeometryValidator.start方法的具体用法?Python QgsGeometryValidator.start怎么用?Python QgsGeometryValidator.start使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在qgis.core.QgsGeometryValidator的用法示例。


在下文中一共展示了QgsGeometryValidator.start方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: MapToolCapture

# 需要导入模块: from qgis.core import QgsGeometryValidator [as 别名]
# 或者: from qgis.core.QgsGeometryValidator import start [as 别名]

#.........这里部分代码省略.........

    def _undo(self):
        if (self._rubberBand is not None):
            rubberBandSize = self._rubberBand.numberOfVertices()
            moveRubberBandSize = self._moveRubberBand.numberOfVertices()

            if (rubberBandSize < 1 or len(self._mapPointList) < 1):
                return

            self._rubberBand.removePoint(-1)

            if (rubberBandSize > 1):
                if (moveRubberBandSize > 1):
                    point = self._rubberBand.getPoint(0, rubberBandSize - 2)
                    self._moveRubberBand.movePoint(moveRubberBandSize - 2, point)
            else:
                self._moveRubberBand.reset(self.geometryType())

            self._mapPointList.pop()
            self._validateGeometry()

    def resetCapturing(self):
        if (self._rubberBand is not None):
            self._rubberBand.reset(self.geometryType())
        if (self._moveRubberBand is not None):
            self._moveRubberBand.reset(self.geometryType())
        self._deleteGeometryValidation()
        del self._mapPointList[:]
        self.canvas().refresh()

    def _deleteGeometryValidation(self):
        if (self._validator is not None):
            self._validator.errorFound.disconnect(self._addGeometryError)
            self._validator.finished.disconnect(self.validationFinished)
            self._validator.deleteLater()
            self._validator = None
        for errorMarker in self._geometryErrorMarkers:
            self.canvas().scene().removeItem(errorMarker)
        del self._geometryErrorMarkers[:]
        self._geometryErrors[:]
        self._tip = ''

    def _validateGeometry(self):
        geometryType = self.geometryType()
        if (geometryType == QGis.Point
                or geometryType == QGis.UnknownGeometry
                or geometryType == QGis.NoGeometry
                or len(self._mapPointList) < 2):
            return

        settings = QSettings()
        if (settings.value('/qgis/digitizing/validate_geometries', 1) == 0):
            return

        self._deleteGeometryValidation()

        geometry = None  # QgsGeometry()

        if (geometryType == QGis.Line):
            geometry = QgsGeometry.fromPolyline(self._mapPointList)
        elif (geometryType == QGis.Polygon):
            if (len(self._mapPointList) < 3):
                return
            closed = list(self._mapPointList)
            closed.append(self._mapPointList[0])
            geometry = QgsGeometry.fromPolygon([closed])

        if (geometry is None):
            return

        self._validator = QgsGeometryValidator(geometry)
        self._validator.errorFound.connect(self._addGeometryError)
        self._validator.finished.connect(self.validationFinished)
        self._validator.start()

        self._iface.mainWindow().statusBar().showMessage(self.tr('Geometry validation started.'))

    def _addGeometryError(self, error):
        self._geometryErrors.append(error)

        if (self._tip != ''):
            self._tip += '\n'
        self._tip += error.what()

        if (error.hasWhere()):
            marker = QgsVertexMarker(self.canvas())
            marker.setCenter(error.where())
            marker.setIconType(QgsVertexMarker.ICON_X)
            marker.setPenWidth(2)
            marker.setToolTip(error.what())
            marker.setColor(Qt.green)
            marker.setZValue(marker.zValue() + 1)
            self._geometryErrorMarkers.append(marker)

        self._iface.mainWindow().statusBar().showMessage(error.what())
        if (self._tip != ''):
            self._iface.mainWindow().statusBar().setToolTip(self._tip)

    def validationFinished(self):
        self._iface.mainWindow().statusBar().showMessage(self.tr('Geometry validation finished.'))
开发者ID:lparchaeology,项目名称:ArkPlan,代码行数:104,代码来源:map_tool_capture.py


注:本文中的qgis.core.QgsGeometryValidator.start方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。