def __init__(self, iface):
        QDialog.__init__(self)
        QtGui.QDialog.__init__(self, None, QtCore.Qt.WindowStaysOnTopHint)
        self.iface = iface
        self.setupUi(self)
        self.field_types = {}
        self.centroids = None
        self.node_layer = None
        self.line_layer = None
        self.node_keys = None
        self.node_fields = None
        self.index = None
        self.matrix = None
        self.clickTool = PointTool(self.iface.mapCanvas())
        self.path = standard_path()
        self.node_id = None

        self.res = PathResults()
        self.link_features = None

        self.do_dist_matrix.setEnabled(False)
        self.load_graph_from_file.clicked.connect(
            self.prepare_graph_and_network)
        self.from_but.clicked.connect(self.search_for_point_from)
        self.to_but.clicked.connect(self.search_for_point_to)
        self.do_dist_matrix.clicked.connect(self.produces_path)
    def find_point(self):
        try:
            point = self.clickTool.point
            nearest = self.index.nearestNeighbor(point, 1)
            self.iface.mapCanvas().setMapTool(None)
            self.clickTool = PointTool(self.iface.mapCanvas())
            node_id = self.node_keys[nearest[0]]

            index_field = self.node_fields.index(self.node_id)
            node_actual_id = node_id[index_field]
            return node_actual_id
        except:
            pass
class OSGBWidget(qtBaseClass, uiWidget):
    def __init__(self, iface, plugin, parent=None):
        qtBaseClass.__init__(self)
        uiWidget.__init__(self, parent)
        self.setupUi(self)
        self.iface = iface
        self.marker = None
        self.tool = None

        self.precisionField.setToolTip("Coordinates precision")
        self.precisionField.setRange(0, 6)
        self.precisionField.setValue(4)

        self._set_icons()
        self._add_validators()
        self._connect_signals(plugin)

    def _set_icons(self):
        self.btnPointTool.setIcon(
            QgsApplication.getThemeIcon("/mActionWhatsThis.svg"))
        self.btnPointTool.setIconSize(QSize(18, 18))

    def _add_validators(self):
        re = QRegExp(
            r'''^(\s*[a-zA-Z]{2}\s*\d{1,4}\s*\d{1,4}\s*|\[out of bounds\])$''')
        self.editCoords.setValidator(QRegExpValidator(re, self))

        re = QRegExp(
            "^\s*[-+]?[0-9]*\.?[0-9]+\s*\,\s*[-+]?[0-9]*\.?[0-9]+\s*$")
        self.editLongLat.setValidator(QRegExpValidator(re, self))

    def _connect_signals(self, plugin):
        self.btnPointTool.clicked.connect(self.pickPoint)
        self.iface.mapCanvas().xyCoordinates.connect(self.trackCoords)
        self.editCoords.returnPressed.connect(self.setCoords)
        self.editLongLat.returnPressed.connect(self.setLongLat)
        self.precisionField.valueChanged.connect(self.change_precision)
        self.clipboardCheck.stateChanged.connect(self.change_copy_to_clipboard)

    def _setEditCooordsOnMouseMove(self, pt):
        if not self.tool:
            self.init_tool()

        try:
            os_ref = xy_to_osgb(pt.x(), pt.y(), self.tool.precision)
        except GridRefException as e:
            print(e)
            os_ref = "[out of bounds]"
        self.editCoords.setText(os_ref)

    def _setEditLongLatOnMouseMove(self, pt):
        point_4326 = reproject_point_to_4326(self.iface.mapCanvas(), pt)
        msg = "{:.2f}, {:.2f}".format(point_4326.x(), point_4326.y())
        self.editLongLat.setText(msg)

    def _add_marker(self, point):
        if self.marker:
            self._remove_marker()
        self.marker = gen_marker(self.iface.mapCanvas(), point)

    def _remove_marker(self):
        if self.marker:
            self.iface.mapCanvas().scene().removeItem(self.marker)
            self.marker = None

    def change_precision(self):
        if self.tool:
            self.tool.precision = pow(10, 5 - self.precisionField.value())

    def change_copy_to_clipboard(self):
        if self.tool:
            print(self.clipboardCheck.isChecked())
            self.tool.clipboard_enable = self.clipboardCheck.isChecked()

    def trackCoords(self, pt):
        self._setEditCooordsOnMouseMove(pt)
        self._setEditLongLatOnMouseMove(pt)
        self._remove_marker()

    def setCoords(self):
        try:
            x, y = osgb_to_xy(self.editCoords.text())
            point27700 = QgsPoint(x, y)
            centre_on_point(self.iface.mapCanvas(), point27700)
            self._add_marker(point27700)
        except GridRefException:
            QMessageBox.warning(
                self.iface.mapCanvas(), "Format",
                "The coordinates should be in format XX ### ###")

    def setLongLat(self):
        try:
            longlat = self.editLongLat.text()
            point4326 = point_from_longlat_text(longlat)
            point27700 = reproject_point_from_4326(self.iface.mapCanvas(),
                                                   point4326)
            centre_on_point(self.iface.mapCanvas(), point27700)
            self._add_marker(point27700)
        except GridRefException:
            QMessageBox.warning(
                self.iface.mapCanvas(), "Format",
                "The coordinates should be in format ##.##, ##.##")

    def pickPoint(self):
        self.init_tool()
        self.iface.mapCanvas().setMapTool(self.tool)

    def init_tool(self):
        self.tool = PointTool(self.iface.mapCanvas(),
                              pow(10, self.precisionField.value()),
                              self.clipboardCheck.isChecked())
        self.change_precision()
        self.tool.setButton(self.btnPointTool)
 def pickPoint(self):
     tool = PointTool(self.iface.mapCanvas())
     tool.setButton(self.btnPointTool)
     self.iface.mapCanvas().setMapTool(tool)
 def init_tool(self):
     self.tool = PointTool(self.iface.mapCanvas(),
                           pow(10, self.precisionField.value()),
                           self.clipboardCheck.isChecked())
     self.change_precision()
     self.tool.setButton(self.btnPointTool)
Beispiel #6
0
class OSGBWidget(qtBaseClass, uiWidget):
    def __init__(self, iface, plugin, precision_field, parent=None):
        qtBaseClass.__init__(self)
        uiWidget.__init__(self, parent)
        self.setupUi(self)
        self.iface = iface
        self.marker = None
        self.precision_field = precision_field
        self.tool = None

        self._set_icons()
        self._add_validators()
        self._connect_signals(plugin)

    def _set_icons(self):
        self.btnClose.setIcon(QgsApplication.getThemeIcon( "/mIconClose.png"))
        self.btnClose.setIconSize(QSize( 18, 18 ))

        self.btnPointTool.setIcon(QgsApplication.getThemeIcon( "/mActionWhatsThis.svg"))
        self.btnPointTool.setIconSize(QSize( 18, 18 ))

    def _add_validators(self):
        re = QRegExp(r'''^(\s*[a-zA-Z]{2}\s*\d{1,4}\s*\d{1,4}\s*|\[out of bounds\])$''')
        self.editCoords.setValidator(QRegExpValidator(re, self))

        re = QRegExp("^\s*[-+]?[0-9]*\.?[0-9]+\s*\,\s*[-+]?[0-9]*\.?[0-9]+\s*$")
        self.editLongLat.setValidator(QRegExpValidator(re, self))

    def _connect_signals(self, plugin):
        self.btnClose.clicked.connect(plugin.actionRun.trigger)
        self.btnPointTool.clicked.connect(self.pickPoint)
        self.iface.mapCanvas().xyCoordinates.connect(self.trackCoords)
        self.editCoords.returnPressed.connect(self.setCoords)
        self.editLongLat.returnPressed.connect(self.setLongLat)
        self.precision_field.valueChanged.connect(self.change_precision)

    def _setEditCooordsOnMouseMove(self, pt):
        # dynamically determine the most sensible precision for the given scale
        log_scale = math.log(self.iface.mapCanvas().scale()) / math.log(10)
        if log_scale >= 6:
          precision = 1000
        elif log_scale >= 5:
          precision = 100
        elif log_scale >= 4:
          precision = 10
        else:
          precision = 1

        if self.tool:
            precision = self.tool.precision

        try:
            os_ref = xy_to_osgb(pt.x(), pt.y(), precision)
        except GridRefException:
            os_ref = "[out of bounds]"
        self.editCoords.setText(os_ref)

    def _setEditLongLatOnMouseMove(self, pt):
        point_4326 = reproject_point_to_4326(self.iface.mapCanvas(), pt)
        msg = "{:.2f}, {:.2f}".format(point_4326.x(), point_4326.y())
        self.editLongLat.setText(msg)

    def _add_marker(self, point):
        if self.marker:
            self._remove_marker()
        self.marker = gen_marker(self.iface.mapCanvas(), point)

    def _remove_marker(self):
        if self.marker:
            self.iface.mapCanvas().scene().removeItem(self.marker)
            self.marker = None

    def change_precision(self):
        if self.tool:
            self.tool.precision = pow(10, 5 - self.precision_field.value())

    def trackCoords(self, pt):
        self._setEditCooordsOnMouseMove(pt)
        self._setEditLongLatOnMouseMove(pt)
        self._remove_marker()

    def setCoords(self):
        try:
          x,y = osgb_to_xy(self.editCoords.text())
          point27700 = QgsPoint(x,y)
          centre_on_point(self.iface.mapCanvas(), point27700)
          self._add_marker(point27700)
        except GridRefException:
            QMessageBox.warning(
              self.iface.mapCanvas(),
              "Format",
              "The coordinates should be in format XX ### ###")

    def setLongLat(self):
        try:
          longlat = self.editLongLat.text()
          point4326 = point_from_longlat_text(longlat)
          point27700 = reproject_point_from_4326(self.iface.mapCanvas(), point4326)
          centre_on_point(self.iface.mapCanvas(), point27700)
          self._add_marker(point27700)
        except GridRefException:
            QMessageBox.warning(
              self.iface.mapCanvas(),
              "Format",
              "The coordinates should be in format ##.##, ##.##")

    def pickPoint(self):
        self.tool = PointTool(self.iface.mapCanvas(), pow(10,self.precision_field.value()))
        self.change_precision()
        self.tool.setButton(self.btnPointTool)
        self.iface.mapCanvas().setMapTool(self.tool)
Beispiel #7
0
 def pickPoint(self):
     self.tool = PointTool(self.iface.mapCanvas(), pow(10,self.precision_field.value()))
     self.change_precision()
     self.tool.setButton(self.btnPointTool)
     self.iface.mapCanvas().setMapTool(self.tool)
class OSGBWidget(qtBaseClass, uiWidget):
    def __init__(self, iface, plugin, parent=None):
        qtBaseClass.__init__(self)
        uiWidget.__init__(self, parent)
        self.setupUi(self)
        self.iface = iface
        self.marker = None
        self.tool = None

        self.precisionField.setToolTip("Coordinates precision")
        self.precisionField.setRange(0, 6)
        self.precisionField.setValue(4)

        self._set_icons()
        self._add_validators()
        self._connect_signals(plugin)

    def _set_icons(self):
        self.btnPointTool.setIcon(
            QgsApplication.getThemeIcon("/mActionWhatsThis.svg"))
        self.btnPointTool.setIconSize(QSize(18, 18))

    def _add_validators(self):
        re = QRegExp(
            r'''^(\s*[a-zA-Z]{2}\s*\d{1,4}\s*\d{1,4}\s*|\[out of bounds\])$''')
        self.editCoords.setValidator(QRegExpValidator(re, self))

        re = QRegExp(
            "^\s*[-+]?[0-9]*\.?[0-9]+\s*\,\s*[-+]?[0-9]*\.?[0-9]+\s*$")
        self.editLongLat.setValidator(QRegExpValidator(re, self))

    def _connect_signals(self, plugin):
        self.btnPointTool.clicked.connect(self.pickPoint)
        self.iface.mapCanvas().xyCoordinates.connect(self.trackCoords)
        self.editCoords.returnPressed.connect(self.setCoords)
        self.editLongLat.returnPressed.connect(self.setLongLat)
        self.precisionField.valueChanged.connect(self.change_precision)
        self.clipboardCheck.stateChanged.connect(self.change_copy_to_clipboard)

    def _setEditCooordsOnMouseMove(self, pt):
        if not self.tool:
            self.init_tool()

        try:
            os_ref = xy_to_osgb(pt.x(), pt.y(), self.tool.precision)
        except GridRefException as e:
            print(e)
            os_ref = "[out of bounds]"
        self.editCoords.setText(os_ref)

    def _setEditLongLatOnMouseMove(self, pt):
        point_4326 = reproject_point_to_4326(self.iface.mapCanvas(), pt)
        msg = "{:.2f}, {:.2f}".format(point_4326.x(), point_4326.y())
        self.editLongLat.setText(msg)

    def _add_marker(self, point):
        if self.marker:
            self._remove_marker()
        self.marker = gen_marker(self.iface.mapCanvas(), point)

    def _remove_marker(self):
        if self.marker:
            self.iface.mapCanvas().scene().removeItem(self.marker)
            self.marker = None

    def change_precision(self):
        if self.tool:
            self.tool.precision = pow(10, 5 - self.precisionField.value())

    def change_copy_to_clipboard(self):
        if self.tool:
            print(self.clipboardCheck.isChecked())
            self.tool.clipboard_enable = self.clipboardCheck.isChecked()

    def trackCoords(self, pt):
        self._setEditCooordsOnMouseMove(pt)
        self._setEditLongLatOnMouseMove(pt)
        self._remove_marker()

    def setCoords(self):
        try:
            x, y = osgb_to_xy(self.editCoords.text())
            point27700 = QgsPoint(x, y)
            centre_on_point(self.iface.mapCanvas(), point27700)
            self._add_marker(point27700)
        except GridRefException:
            QMessageBox.warning(
              self.iface.mapCanvas(),
              "Format",
              "The coordinates should be in format XX ### ###")

    def setLongLat(self):
        try:
            longlat = self.editLongLat.text()
            point4326 = point_from_longlat_text(longlat)
            point27700 = reproject_point_from_4326(self.iface.mapCanvas(),
                                                   point4326)
            centre_on_point(self.iface.mapCanvas(), point27700)
            self._add_marker(point27700)
        except GridRefException:
            QMessageBox.warning(
              self.iface.mapCanvas(),
              "Format",
              "The coordinates should be in format ##.##, ##.##")

    def pickPoint(self):
        self.init_tool()
        self.iface.mapCanvas().setMapTool(self.tool)

    def init_tool(self):
        self.tool = PointTool(self.iface.mapCanvas(),
                              pow(10, self.precisionField.value()),
                              self.clipboardCheck.isChecked())
        self.change_precision()
        self.tool.setButton(self.btnPointTool)
 def init_tool(self):
     self.tool = PointTool(self.iface.mapCanvas(),
                           pow(10, self.precisionField.value()),
                           self.clipboardCheck.isChecked())
     self.change_precision()
     self.tool.setButton(self.btnPointTool)