def __init__(self, canvas, pickMode = 'selection'):
     self.canvas = canvas
     QgsMapToolIdentify.__init__(self, canvas)
     self.setCursor(QCursor())
     if pickMode == 'all':
         self.selectionMode = self.TopDownStopAtFirst
     elif pickMode == 'selection':
         self.selectionMode = self.LayerSelection
     elif pickMode == 'active':
         self.selectionMode = self.ActiveLayer
Exemple #2
0
    def canvasReleaseEvent(self, mouseEvent):
        theLayer = self.mCanvas.currentLayer()
        if theLayer is None:
            return
        if theLayer.type() != QgsMapLayer.VectorLayer:
            return
        if theLayer.featureCount() == 0:
            return

        qgsMapToolIndentify = QgsMapToolIdentify(self.mCanvas)
        resultList = qgsMapToolIndentify.identify(mouseEvent.x(),
                                                  mouseEvent.y(), -1)
        if resultList == []:  # no feature selected, pan the canvas
            if self.mDragging == True:
                self.mCanvas.panActionEnd(mouseEvent.pos())
                self.mDragging = False
            else:  # add pan to mouse cursor
                # transform the mouse pos to map coordinates
                center = self.mCanvas.getCoordinateTransform().toMapPoint(
                    mouseEvent.x(), mouseEvent.y())
                self.mCanvas.setCenter(center)
                self.mCanvas.refresh()
        else:  # select the features
            theFeature = (resultList[0]).mFeature
            if RdbLinkObject.isMyFeature(theFeature) == True:
                nodeId = theFeature.attribute('start_node_id')
                self.mNaviDlg.addNode(nodeId)
            return
Exemple #3
0
 def __init__(self, canvas, dlg):
     global features
     QgsMapToolIdentify.__init__(self, canvas)
     self.canvas = canvas
     self.dlg = dlg
     self.select_id = None
     self.tool = QgsMapToolIdentify(self.canvas)
 def canvasReleaseEvent(self, event):
     x = event.pos().x()
     y = event.pos().y()
     
     # TODO layer automatisch speichern damit das polygon eine id von der db kriegt
     
     # Ugly hack to identify the clicked element. For some reasons if InfoPointTool inherits from QgsMapToolIdentify,
     # canvasRealeaseEvent isn't called.
     tool = QgsMapToolIdentify(self.canvas)
     results = tool.identify(x,y, tool.ActiveLayer, tool.AllLayers)
     if not results:
         return
     
     guiName = self.canvas.currentLayer().name()
     dbName = self.canvas.currentLayer().dataProvider().dataSourceUri().split(' ')[0].split('=')[1].replace("'", '')
     
     result = results[0]
     
     feat = result.mFeature
     attrs = feat.attributes()
     fields = feat.fields().toList()
     fieldId = None
     
     for i, attr in enumerate(attrs):
         name = fields[i].name()
         if name == 'id' and attr is not None:
             fieldId = str(attr)
             break
     
     if fieldId is None:
         QMessageBox.warning(None, "Ungespeicherte Aenderungen", "Sie muessen das Polygon zuerst speichern")
         return
     
     DynamicGuiLoader(dbName, guiName, fieldId)
 def __init__(self, canvas, layer):
     """ Constructor.
     """
     QgsMapToolIdentify.__init__(self, canvas)
     self.canvas = canvas
     self.layer = layer
     self.setCursor(Qt.CrossCursor)
    def __init__(self, iface, parent=None, layer=None):
        QgsMapToolIdentify.__init__(self, iface.mapCanvas())
        self.canvas = iface.mapCanvas()
        self.iface = iface
        self.layer = layer
        self.parent = parent

        self.cursor = QCursor(QPixmap(["16 16 3 1",
                                       "      c None",
                                       ".     c #FF0000",
                                       "+     c #FFFFFF",
                                       "                ",
                                       "       +.+      ",
                                       "      ++.++     ",
                                       "     +.....+    ",
                                       "    +.     .+   ",
                                       "   +.   .   .+  ",
                                       "  +.    .    .+ ",
                                       " ++.    .    .++",
                                       " ... ...+... ...",
                                       " ++.    .    .++",
                                       "  +.    .    .+ ",
                                       "   +.   .   .+  ",
                                       "   ++.     .+   ",
                                       "    ++.....+    ",
                                       "      ++.++     ",
                                       "       +.+      "]))
    def __init__(self, iface, action, plugin_dir, spinbox):
        self.canvas = iface.mapCanvas()
        self.iface = iface
        self.action = action
        self.icon_path = os.path.join(plugin_dir,"icons")
        self.spinbox = spinbox

        self.rubberBand = QgsRubberBand(self.canvas, QgsWkbTypes.GeometryType(3))
        self.rubberBand.setWidth(3)
        self.rubberBand.setStrokeColor(QColor(254,0,0))

        self.snap_mark = QgsVertexMarker(self.canvas)
        self.snap_mark.setColor(QColor(0, 0, 255))
        self.snap_mark.setPenWidth(2)
        self.snap_mark.setIconType(QgsVertexMarker.ICON_BOX)
        self.snap_mark.setIconSize(10)

        QgsMapToolIdentify.__init__(self, self.canvas)

        self.selectFeatureMode = True
        self.firstPointMode = False
        self.secondPointMode = False
        self.objectSizeMode = False

        self.firstPoint_locate = None
        self.linestring = None

        self.dist = self.spinbox.value()

        self.canvas.layersChanged.connect(self.setPolygonLayers)
Exemple #8
0
 def __init__(self, street_browser_dk, iface, esu_layer, toolbar, db,
              mapper):
     """
     Build on init of QgsMapToolIdentify class for custom RN functionality.
     :param street_browser_dk: Street Browser dialog
     :param iface: Qgis interface reference
     :param esu_layer: ESU Graphic layer
     :param toolbar: toolbar instance
     :param db: database connection
     :param mapper: Qdatawidgetmapper of street browser
     """
     self.street_browser_dk = street_browser_dk
     self.iface = iface
     self.canvas = self.iface.mapCanvas()
     self.db = db
     self.zoom_funct = ZoomSelectCanvas(self.iface, self.street_browser_dk,
                                        self.db)
     self.layer = esu_layer
     self.toolbar = toolbar
     # Data widget mapper used in sb
     self.mapper = mapper
     # Set hand cursor
     self.cursor = QCursor(Qt.PointingHandCursor)
     # Create street selector dialog
     self.street_sel_dlg = StreetSelectorDlg()
     self.street_sel_dlg.setWindowFlags(Qt.Window | Qt.WindowTitleHint
                                        | Qt.CustomizeWindowHint)
     # Connect street selector buttons
     self.connect_actions()
     QgsMapToolIdentify.__init__(self, self.canvas)
 def canvasReleaseEvent(self, mouseEvent): 
     theLayer = self.mCanvas.currentLayer()
     if theLayer is None:
         return
     if theLayer.type() != QgsMapLayer.VectorLayer:
         return
     if theLayer.featureCount() == 0:
         return
       
     qgsMapTollIndentify = QgsMapToolIdentify(self.mCanvas)
     resultList = qgsMapTollIndentify.identify(mouseEvent.x(), mouseEvent.y(), -1)
     if resultList == []: # no feature selected, pan the canvas
         if self.mDragging == True:
             self.mCanvas.panActionEnd(mouseEvent.pos())
             self.mDragging = False
         else: # add pan to mouse cursor
             # transform the mouse pos to map coordinates
             center = self.mCanvas.getCoordinateTransform().toMapPoint(mouseEvent.x(), mouseEvent.y())
             self.mCanvas.setCenter(center)
             self.mCanvas.refresh()
     else: # select the features
         self.removeAllSelection()
         featureIdList = []
         for oneResult in resultList:
             featureIdList.append(oneResult.mFeature.id())
         theLayer.select(featureIdList)
         dlg = self.getAppreciateDlg(theLayer, featureIdList)
         dlg.show()
         result = dlg.exec_()
         if result:
             pass
         else:
             pass
         return
 def __init__(self, canvas, pickMode='selection'):
     self.canvas = canvas
     QgsMapToolIdentify.__init__(self, canvas)
     self.setCursor(QCursor())
     if pickMode == 'all':
         self.selectionMode = self.TopDownStopAtFirst
     elif pickMode == 'selection':
         self.selectionMode = self.LayerSelection
     elif pickMode == 'active':
         self.selectionMode = self.ActiveLayer
    def __init__(self, iface):
        QgsMapToolIdentify.__init__(self, iface.mapCanvas())
        self.iface = iface
        FieldRestrictionTypeUtilsMixin.__init__(self, iface)

        try:
            self.SIGN_TYPES = QgsProject.instance().mapLayersByName(
                "SignTypes")[0]
            self.MHTC_CHECK_ISSUE_TYPES = QgsProject.instance(
            ).mapLayersByName("MHTC_CheckIssueTypes")[0]
        except:
            None  # if "Signs" is not present
Exemple #12
0
 def canvasPressEvent(self, e):
     '''
     override, remember feature on click and move marker (create one if not
     drawn yet)
     '''
     if self._picked_feature is None:
         features = QgsMapToolIdentify(self.canvas).identify(
             e.pos().x(),
             e.pos().y(), self._layers,
             QgsMapToolIdentify.TopDownStopAtFirst)
         if len(features) == 0:
             return
         feature = features[0].mFeature
         self._picked_feature = feature.id()
     # there is a feature -> drag it
     self._dragging = True
     self.canvas.setCursor(self.drag_cursor)
     # not marked yet -> mark position
     if not self._marker:
         color = QColor(0, 0, 255)
         color.setAlpha(100)
         self._marker = QgsVertexMarker(self.canvas)
         self._marker.setColor(color)
         self._marker.setIconSize(10)
         self._marker.setIconType(QgsVertexMarker.ICON_CIRCLE)
         self._marker.setPenWidth(10)
     point = self.toMapCoordinates(e.pos())
     self._marker.setCenter(point)
Exemple #13
0
class ClickTool(QgsMapToolIdentify):
    def __init__(self, canvas, dlg):
        global features
        QgsMapToolIdentify.__init__(self, canvas)
        self.canvas = canvas
        self.dlg = dlg
        self.select_id = None
        self.tool = QgsMapToolIdentify(self.canvas)

    # 滑鼠按下時動作
    def canvasPressEvent(self, event):
        global point, features
        layer = self.dlg.mMapLayerComboBox.currentLayer()
        # point類型為QgsPointXY
        point = self.toMapCoordinates(self.canvas.mouseLastXY())
        # QgsPointXY轉list
        point = list(point)
        #print("\n---\n")
        #print("click (x,y): ", point)

        # 挑最上層layer選
        features = self.tool.identify(event.x(), event.y(), [layer],
                                      self.tool.TopDownStopAtFirst)
        #print(event.x(), event.y())


        if len(features) > 0:
            # here you get the selected feature
            feature = features[0].mFeature
            #print(list(feature.geometry().asMultiPolyline()))
            self.dlg.label_coor.setText("[{:<10.1f}, {:>10.1f}]".format(point[0], point[1]))
            #print("select ID: ", self.select_id)
            #print("click x,y: ", point[0], point[1])
            QMessageBox.information(self.dlg, "提示","您點擊了座標:[{:.1f} , {:.1f}]\n該圖徵ID:{:d}"
                                    .format(point[0], point[1], feature.id()))
Exemple #14
0
    def canvasPressEvent(self, event):
        """ Sobrescrevendo método da QgsMapTool herdada para que execute
            as funcionalidades desejadas.
            Usamos a QgsMapToolIdentify para identificar feições de
            camadas no mapa. Para mais Informações consulte a documentação
        """

        if not self.municipios_layer.isValid():
            return
        # pega a camada de municipios
        layer = self.municipios_layer

        # Aqui estamos definindo como a identificação deve ser feita
        inicio_identificacao = QgsMapToolIdentify.TopDownStopAtFirst

        # usando  a ferramenta para ver se o local onde clicamos (x,y do evento de clique)
        # pertence a uma feição da camada
        feicoes_clicadas = QgsMapToolIdentify(self.canvas).identify(
            event.x(),
            event.y(),
            [layer],
            inicio_identificacao
        )

        # se existir, seleciona só a primeira feição retornada na identificação
        if len(feicoes_clicadas) > 0:
            municipio_selecionado = feicoes_clicadas[0].mFeature
            self.municipios_layer.select(municipio_selecionado.id())
Exemple #15
0
 def __init__(self, gtoObj, canvas, config, cursorstyle=Qt.CrossCursor):
     self.info = gtoObj.info
     self.debug = gtoObj.debug
     self.canvas = canvas
     self.layer = None
     QgsMapToolIdentify.__init__(self, canvas)
     try:
         cursor = QCursor()
         cursor.setShape(cursorstyle)
         self.setCursor(cursor)
         # metadata
         layer = config.get("layer", None)
         if layer is not None:
             self.layer = QgsProject.instance().mapLayersByName(layer)[0]
         self.smallest = config.get("smallest", True)
         if self.debug: self.info.log("SelectPolygonTool::init")
     except Exception as e:
         self.info.err(e)
Exemple #16
0
    def run(self):
        """Run method that performs all the real work"""

        # Create the dialog with elements (after translation) and keep reference
        # Only create GUI ONCE in callback, so that it will only load when the plugin is started
        if self.first_start == True:
            self.first_start = False
            self.finish = False
            self.dlg = TestPluginDialog()
            self.maptool = QgsMapToolIdentify(self.canvas)
            self.clicktool = ClickTool(self.canvas, self.dlg)
            self.mousetool = MouseTool(self.canvas, self.dlg)

            # 圖層分類 (MultiLineString, MultiPolygon)
            layer_group = [[],[]]
            # 不要用self.canvas.layers() 沒打勾的layer無法獲取
            layers = list(QgsProject().instance().mapLayers().values())  # dict轉list
            for l in layers:  # QgsVectorLayer
                if l.wkbType() == QgsWkbTypes.MultiLineString and l.type() == QgsMapLayer.VectorLayer:
                    layer_group[0].append(l)
                if l.wkbType() == QgsWkbTypes.MultiPolygon and l.type() == QgsMapLayer.VectorLayer:
                    layer_group[1].append(l)
            # 控制UI連動function
            self.dlg.btn_start.clicked.connect(self.start_calc)
            self.dlg.btn_clicktool.clicked.connect(self.show_clicktool)
            self.dlg.btn_mousetool.clicked.connect(self.show_mousetool)
            self.dlg.btn_clear.clicked.connect(self.reset)
            self.dlg.btn_save.clicked.connect(self.save_to_shp)
            self.dlg.mMapLayerComboBox.layerChanged.connect(self.set_layer)
            self.dlg.mMapLayerComboBox_2.layerChanged.connect(self.set_layer_2)
            self.mousetool.featureIdentified.connect(self.identify_select)
            # 圖層下拉框 設定過濾規則
            # 河道
            self.dlg.mMapLayerComboBox.setFilters(QgsMapLayerProxyModel.VectorLayer)
            self.dlg.mMapLayerComboBox.setExceptedLayerList(layer_group[1])  # 只要河道不要集水區
            # 集水區
            self.dlg.mMapLayerComboBox_2.setFilters(QgsMapLayerProxyModel.VectorLayer)
            self.dlg.mMapLayerComboBox_2.setExceptedLayerList(layer_group[0])  # 只要集水區不要河道
            self.update_ = Update(self.dlg)
            self.layer = self.dlg.mMapLayerComboBox.currentLayer()
            self.layer_2 = self.dlg.mMapLayerComboBox_2.currentLayer()
            # 進度條
            self.dlg.progressBar.setMinimum(0)
            self.dlg.progressBar.setFormat("已計算: %d %%" % (self.dlg.progressBar.value()))

        # show the dialog
        self.dlg.show()
        # Run the dialog event loop
        result = self.dlg.exec_()

        # See if OK was pressed
        if result:
            self.reset()
            self.unset_maptool()
            self.dlg.label_coor.setText("請使用選取工具點擊圖上任一圖徵...")
Exemple #17
0
 def canvasReleaseEvent(self, mouseEvent):
     '''
     override, emit first feature found on mouse release
     '''
     if not self._layers:
         return
     features = QgsMapToolIdentify(self.canvas).identify(
         mouseEvent.x(), mouseEvent.y(), self._layers,
         QgsMapToolIdentify.TopDownStopAtFirst)
     if len(features) > 0:
         self.feature_picked.emit(features[0].mFeature.id())
Exemple #18
0
class PointTool(QgsMapTool):
    trigger = pyqtSignal(QgsFeature)

    def __init__(self, canvas):
        QgsMapTool.__init__(self, canvas)
        self.canvas = canvas
        self.identifier = QgsMapToolIdentify(canvas)

    def canvasPressEvent(self, e):
        x = e.pos().x()
        y = e.pos().y()

        point = self.canvas.getCoordinateTransform().toMapCoordinates(x, y)
        indentifiedFeatures = self.identifier.identify(
            e.x(), e.y(), self.identifier.TopDownAll)
        if len(indentifiedFeatures) > 0:
            self.trigger.emit(indentifiedFeatures[0].mFeature)
Exemple #19
0
 def __init__(self, canvas, pickMode='all', cursorstyle=Qt.CrossCursor, layers=None):
     self.canvas = canvas
     QgsMapToolIdentify.__init__(self, canvas)
     self.setCursorStyle(cursorstyle)
     self.setPickMode(pickMode)
     self.layers = layers
Exemple #20
0
 def __init__(self, canvas, layerList, DEM=None):
     self.canvas = canvas
     self.layerList = layerList
     self.DEM = DEM
     QgsMapToolIdentify.__init__(self, canvas)
     self.setCursor(QCursor())
Exemple #21
0
 def __init__(self, iface):
     QgsMapToolIdentify.__init__(self, iface.mapCanvas())
     self.iface = iface
     FieldRestrictionTypeUtilsMixin.__init__(self, iface)
 def __init__(self, canvas, targetLayer):
     self.canvas = canvas
     self.targetLayer = targetLayer
     QgsMapToolIdentify.__init__(self, canvas)
     self.setCursor(QCursor())
Exemple #23
0
 def action_identify_triggered(self):
     self.maptool = QgsMapToolIdentify(self.mapCanvas)
     self.mapCanvas.setMapTool(self.maptool)
Exemple #24
0
 def __init__(self, canvas, layerType='AllLayers'):
     QgsMapToolIdentify.__init__(self, canvas)
     self.layerType = getattr(QgsMapToolIdentify, layerType)
     self.canvas = canvas
     self.setCursor(QCursor(Qt.PointingHandCursor))
     self.applicationSettings = ApplicationSettings()
Exemple #25
0
 def __init__(self, canvas):
     self.canvas = canvas
     QgsMapToolIdentify.__init__(self, canvas)
     self.setCursor(QCursor())
 def __init__(self, canvas, targetLayer):
     self.canvas = canvas
     self.targetLayer = targetLayer
     QgsMapToolIdentify.__init__(self, canvas)
     self.setCursor(QCursor())
Exemple #27
0
 def __init__(self, canvas):
     QgsMapTool.__init__(self, canvas)
     self.canvas = canvas
     self.identifier = QgsMapToolIdentify(canvas)
Exemple #28
0
 def __init__(self, canvas):
     self.canvas = canvas
     QgsMapToolIdentify.__init__(self, canvas)
     self.setCursor(QCursor(QPixmap(Cursor), 1, 6))
Exemple #29
0
 def __init__(self, iface):
     QgsMapToolIdentify.__init__(self, iface.mapCanvas())
     self.iface = iface
 def __init__(self, canvas, layerType='AllLayers'):
     QgsMapToolIdentify.__init__(self, canvas)
     self.layerType = getattr(QgsMapToolIdentify, layerType)
     self.canvas = canvas
     self.setCursor(QCursor())
 def __init__(self, canvas):
     self.canvas = canvas
     QgsMapToolIdentify.__init__(self, canvas)
Exemple #32
0
 def __init__(self, canvas):
     self.canvas = canvas
     QgsMapToolIdentify.__init__(self, canvas)
     self.setCursor(QCursor(QPixmap(Cursor), 1, 6))
Exemple #33
0
 def __init__(self, parentInstance, targetLayer):
     self.parentInstance = parentInstance
     self.canvas = parentInstance.canvas
     self.targetLayer = targetLayer
     QgsMapToolIdentify.__init__(self, self.canvas)
     self.setCursor(QCursor())