def registerDatabaseActions(self, mainWindow): action = QAction(QApplication.translate("DBManagerPlugin", "&Re-connect"), self) mainWindow.registerAction( action, QApplication.translate("DBManagerPlugin", "&Database"), self.reconnectActionSlot ) if self.schemas() is not None: action = QAction(QApplication.translate("DBManagerPlugin", "&Create schema"), self) mainWindow.registerAction( action, QApplication.translate("DBManagerPlugin", "&Schema"), self.createSchemaActionSlot ) action = QAction(QApplication.translate("DBManagerPlugin", "&Delete (empty) schema"), self) mainWindow.registerAction( action, QApplication.translate("DBManagerPlugin", "&Schema"), self.deleteSchemaActionSlot ) action = QAction(QApplication.translate("DBManagerPlugin", "Delete selected item"), self) mainWindow.registerAction(action, None, self.deleteActionSlot) action.setShortcuts(QKeySequence.Delete) action = QAction( QIcon(":/db_manager/actions/create_table"), QApplication.translate("DBManagerPlugin", "&Create table"), self ) mainWindow.registerAction( action, QApplication.translate("DBManagerPlugin", "&Table"), self.createTableActionSlot ) action = QAction( QIcon(":/db_manager/actions/edit_table"), QApplication.translate("DBManagerPlugin", "&Edit table"), self ) mainWindow.registerAction(action, QApplication.translate("DBManagerPlugin", "&Table"), self.editTableActionSlot) action = QAction( QIcon(":/db_manager/actions/del_table"), QApplication.translate("DBManagerPlugin", "&Delete table/view"), self, ) mainWindow.registerAction( action, QApplication.translate("DBManagerPlugin", "&Table"), self.deleteTableActionSlot ) action = QAction(QApplication.translate("DBManagerPlugin", "&Empty table"), self) mainWindow.registerAction( action, QApplication.translate("DBManagerPlugin", "&Table"), self.emptyTableActionSlot ) if self.schemas() is not None: action = QAction(QApplication.translate("DBManagerPlugin", "&Move to schema"), self) action.setMenu(QMenu(mainWindow)) def invoke_callback(): return mainWindow.invokeCallback(self.prepareMenuMoveTableToSchemaActionSlot) action.menu().aboutToShow.connect(invoke_callback) mainWindow.registerAction(action, QApplication.translate("DBManagerPlugin", "&Table"))
def registerDatabaseActions(self, mainWindow): action = QAction(QApplication.translate("DBManagerPlugin", "&Re-connect"), self) mainWindow.registerAction(action, QApplication.translate("DBManagerPlugin", "&Database"), self.reconnectActionSlot) if self.schemas() is not None: action = QAction(QApplication.translate("DBManagerPlugin", "&Create Schema…"), self) mainWindow.registerAction(action, QApplication.translate("DBManagerPlugin", "&Schema"), self.createSchemaActionSlot) action = QAction(QApplication.translate("DBManagerPlugin", "&Delete (Empty) Schema"), self) mainWindow.registerAction(action, QApplication.translate("DBManagerPlugin", "&Schema"), self.deleteSchemaActionSlot) action = QAction(QApplication.translate("DBManagerPlugin", "Delete Selected Item"), self) mainWindow.registerAction(action, None, self.deleteActionSlot) action.setShortcuts(QKeySequence.Delete) action = QAction(QgsApplication.getThemeIcon("/mActionCreateTable.svg"), QApplication.translate("DBManagerPlugin", "&Create Table…"), self) mainWindow.registerAction(action, QApplication.translate("DBManagerPlugin", "&Table"), self.createTableActionSlot) action = QAction(QgsApplication.getThemeIcon("/mActionEditTable.svg"), QApplication.translate("DBManagerPlugin", "&Edit Table…"), self) mainWindow.registerAction(action, QApplication.translate("DBManagerPlugin", "&Table"), self.editTableActionSlot) action = QAction(QgsApplication.getThemeIcon("/mActionDeleteTable.svg"), QApplication.translate("DBManagerPlugin", "&Delete Table/View…"), self) mainWindow.registerAction(action, QApplication.translate("DBManagerPlugin", "&Table"), self.deleteTableActionSlot) action = QAction(QApplication.translate("DBManagerPlugin", "&Empty Table…"), self) mainWindow.registerAction(action, QApplication.translate("DBManagerPlugin", "&Table"), self.emptyTableActionSlot) if self.schemas() is not None: action = QAction(QApplication.translate("DBManagerPlugin", "&Move to Schema"), self) action.setMenu(QMenu(mainWindow)) def invoke_callback(): return mainWindow.invokeCallback(self.prepareMenuMoveTableToSchemaActionSlot) action.menu().aboutToShow.connect(invoke_callback) mainWindow.registerAction(action, QApplication.translate("DBManagerPlugin", "&Table"))
def add_action( self, icon_path, text, callback, enabled_flag=True, checkable=False, add_to_menu=True, add_to_toolbar=True, status_tip=None, whats_this=None, menu=None, parent=None): icon = QIcon(icon_path) action = QAction(icon, text, parent) action.triggered.connect(callback) action.setEnabled(enabled_flag) action.setCheckable(checkable) if status_tip is not None: action.setStatusTip(status_tip) if whats_this is not None: action.setWhatsThis(whats_this) if menu is not None: action.setMenu(menu) if add_to_toolbar: self.toolbar.addAction(action) if add_to_menu: self.iface.addPluginToVectorMenu( self.menu, action) self.actions.append(action) return action
def initGui(self): # Declare instance attributes self.actions = [] #self.menu = u'빠른 작업 도구' self.menuBar = self.iface.mainWindow().menuBar() self.menu = QMenu(u'빠른 작업 도구', self.menuBar) actions = self.menuBar.actions() lastAction = actions[-1] self.menuBar.insertMenu(lastAction, self.menu) # TODO: We are going to let the user set this up in a future iteration self.toolbar = self.iface.addToolBar(u'빠른 작업 도구') self.toolbar.setObjectName(u'EasyProcessingTool') """Create the menu entries and toolbar icons inside the QGIS GUI.""" icon_path = os.path.join(os.path.dirname(__file__), 'icon', 'Print.png') self.add_action(icon_path, text=u'자동 구역 출력', callback=self.run_AutoDistrictPrinterDialog, parent=self.iface.mainWindow(), add_to_toolbar=True) self.menu.addSeparator() icon_path = os.path.join(os.path.dirname(__file__), 'icon', 'AddLayer.png') self.add_action(icon_path, text=u'다중 레이어 추가', callback=self.run_AddLayerMultiDialog, parent=self.iface.mainWindow(), add_to_toolbar=True) self.menu.addSeparator() icon_path = os.path.join(os.path.dirname(__file__), 'icon', 'AddData.png') self.add_action(icon_path, text=u'길이/면적 속성 입력', callback=self.run_CreateLengthAreaAttributesDialog, parent=self.iface.mainWindow()) self.add_action(icon_path, text=u'중심점 생성', callback=self.run_CreateCenteroidLayerDialog, parent=self.iface.mainWindow()) fieldAction = QAction(QIcon(icon_path), '길이/면적 속성 입력', self.iface.mainWindow()) fieldMenu = QMenu(self.iface.mainWindow()) fieldAction1 = QAction('길이/면적 속성 입력', self.iface.mainWindow()) fieldAction2 = QAction('중심점 생성', self.iface.mainWindow()) fieldMenu.addAction(fieldAction1) fieldMenu.addAction(fieldAction2) fieldAction.setMenu(fieldMenu) self.toolbar.addAction(fieldAction) fieldAction.triggered.connect( self.run_CreateLengthAreaAttributesDialog) fieldAction1.triggered.connect( self.run_CreateLengthAreaAttributesDialog) fieldAction2.triggered.connect(self.run_CreateCenteroidLayerDialog) self.actions.append(fieldAction) self.menu.addSeparator() icon_path = os.path.join(os.path.dirname(__file__), 'icon', 'KML.png') #ImportKMLDialog self.add_action(icon_path, text=u'KML 가져오기', callback=self.run_ImportKMLDialog, parent=self.iface.mainWindow()) #ExportKMLDialog self.add_action(icon_path, text=u'KML 내보내기', callback=self.run_ExportKMLDialog, parent=self.iface.mainWindow()) kmlAction = QAction(QIcon(icon_path), 'KML 가져오기', self.iface.mainWindow()) kmlMenu = QMenu(self.iface.mainWindow()) kmlAction1 = QAction('KML 가져오기', self.iface.mainWindow()) kmlAction2 = QAction('KML 내보내기', self.iface.mainWindow()) kmlMenu.addAction(kmlAction1) kmlMenu.addAction(kmlAction2) kmlAction.setMenu(kmlMenu) self.toolbar.addAction(kmlAction) kmlAction.triggered.connect(self.run_ImportKMLDialog) kmlAction1.triggered.connect(self.run_ImportKMLDialog) kmlAction2.triggered.connect(self.run_ExportKMLDialog) self.actions.append(kmlAction) self.menu.addSeparator() icon_path = os.path.join(os.path.dirname(__file__), 'icon', 'Coordinates.png') self.add_action(icon_path, text=u'레이어 좌표계 설정', callback=self.run_SetCoordinateDialog, parent=self.iface.mainWindow()) self.add_action(icon_path, text=u'레이어 좌표계 변환', callback=self.run_TranslateCoordinateDialog, parent=self.iface.mainWindow()) crsAction = QAction(QIcon(icon_path), '레이어 좌표계 설정', self.iface.mainWindow()) crsMenu = QMenu(self.iface.mainWindow()) crsAction1 = QAction('레이어 좌표계 설정', self.iface.mainWindow()) crsAction2 = QAction('레이어 좌표계 변환', self.iface.mainWindow()) crsMenu.addAction(crsAction1) crsMenu.addAction(crsAction2) crsAction.setMenu(crsMenu) self.toolbar.addAction(crsAction) crsAction.triggered.connect(self.run_SetCoordinateDialog) crsAction1.triggered.connect(self.run_SetCoordinateDialog) crsAction2.triggered.connect(self.run_TranslateCoordinateDialog) self.actions.append(crsAction) self.menu.addSeparator() icon_path = os.path.join(os.path.dirname(__file__), 'icon', 'CalculateArea.png') self.add_action(icon_path, text='래스터 면적 추출', callback=self.run_CalculateRasterArea, parent=self.iface.mainWindow(), add_to_toolbar=True) self.menu.addSeparator() self.add_action(None, text='플러그인 정보', callback=self.run_PluginInfoDialog, parent=self.iface.mainWindow())
class LatLonTools: def __init__(self, iface): self.iface = iface self.canvas = iface.mapCanvas() self.crossRb = QgsRubberBand(self.canvas, QgsWkbTypes.LineGeometry) self.crossRb.setColor(Qt.red) def initGui(self): '''Initialize Lot Lon Tools GUI.''' # Initialize the Settings Dialog box self.settingsDialog = SettingsWidget(self, self.iface, self.iface.mainWindow()) self.mapTool = CopyLatLonTool(self.settingsDialog, self.iface) self.showMapTool = ShowOnMapTool(self.settingsDialog, self.iface) self.toMGRSDialog = ToMGRSWidget(self.iface, self.iface.mainWindow()) self.MGRStoLayerDialog = MGRStoLayerWidget(self.iface, self.iface.mainWindow()) # Add Interface for Coordinate Capturing icon = QIcon(os.path.dirname(__file__) + "/images/copyicon.png") self.copyAction = QAction(icon, "Copy Latitude, Longitude", self.iface.mainWindow()) self.copyAction.triggered.connect(self.startCapture) self.copyAction.setCheckable(True) self.iface.addToolBarIcon(self.copyAction) self.iface.addPluginToMenu("Lat Lon Tools", self.copyAction) # Add Interface for Zoom to Coordinate icon = QIcon(os.path.dirname(__file__) + "/images/zoomicon.png") self.zoomToAction = QAction(icon, "Zoom To Latitude, Longitude", self.iface.mainWindow()) self.zoomToAction.triggered.connect(self.showZoomToDialog) self.iface.addPluginToMenu('Lat Lon Tools', self.zoomToAction) self.canvas.mapToolSet.connect(self.unsetTool) self.zoomToDialog = ZoomToLatLon(self, self.iface, self.iface.mainWindow()) self.iface.addDockWidget(Qt.LeftDockWidgetArea, self.zoomToDialog) self.zoomToDialog.hide() # Add Interface for External Map icon = QIcon(os.path.dirname(__file__) + "/images/mapicon.png") self.externMapAction = QAction(icon, "Show in External Map", self.iface.mainWindow()) self.externMapAction.triggered.connect(self.setShowMapTool) self.externMapAction.setCheckable(True) self.iface.addToolBarIcon(self.externMapAction) self.iface.addPluginToMenu("Lat Lon Tools", self.externMapAction) # Add Interface for Multi point zoom icon = QIcon(os.path.dirname(__file__) + '/images/multizoom.png') self.multiZoomToAction = QAction(icon, "Multi-location Zoom", self.iface.mainWindow()) self.multiZoomToAction.triggered.connect(self.multiZoomTo) self.iface.addPluginToMenu('Lat Lon Tools', self.multiZoomToAction) self.multiZoomDialog = MultiZoomWidget(self, self.settingsDialog, self.iface.mainWindow()) self.multiZoomDialog.hide() self.multiZoomDialog.setFloating(True) # Add To MGRS conversion icon = QIcon(os.path.dirname(__file__) + '/images/mgrs2point.png') icon2 = QIcon(os.path.dirname(__file__) + '/images/point2mgrs.png') menu = QMenu() menu.addAction(icon, "MGRS to Geometry", self.MGRStoLayer) menu.addAction(icon2, "Geometry to MGRS", self.toMGRS) self.toMGRSAction = QAction(icon2, "MGRS Conversions", self.iface.mainWindow()) self.toMGRSAction.setMenu(menu) self.iface.addPluginToMenu('Lat Lon Tools', self.toMGRSAction) # Initialize the Settings Dialog Box settingsicon = QIcon( os.path.dirname(__file__) + '/images/settings.png') self.settingsAction = QAction(settingsicon, "Settings", self.iface.mainWindow()) self.settingsAction.triggered.connect(self.settings) self.iface.addPluginToMenu('Lat Lon Tools', self.settingsAction) # Help helpicon = QIcon(os.path.dirname(__file__) + '/images/help.png') self.helpAction = QAction(helpicon, "Help", self.iface.mainWindow()) self.helpAction.triggered.connect(self.help) self.iface.addPluginToMenu('Lat Lon Tools', self.helpAction) def unsetTool(self, tool): '''Uncheck the Copy Lat Lon tool''' try: if not isinstance(tool, CopyLatLonTool): self.copyAction.setChecked(False) self.multiZoomDialog.stopCapture() self.mapTool.capture4326 = False if not isinstance(tool, ShowOnMapTool): self.externMapAction.setChecked(False) except: pass def unload(self): '''Unload LatLonTools from the QGIS interface''' self.zoomToDialog.removeMarker() self.multiZoomDialog.removeMarkers() self.canvas.unsetMapTool(self.mapTool) self.canvas.unsetMapTool(self.showMapTool) self.iface.removePluginMenu('Lat Lon Tools', self.copyAction) self.iface.removeToolBarIcon(self.copyAction) self.iface.removePluginMenu('Lat Lon Tools', self.externMapAction) self.iface.removeToolBarIcon(self.externMapAction) self.iface.removePluginMenu('Lat Lon Tools', self.zoomToAction) self.iface.removePluginMenu('Lat Lon Tools', self.multiZoomToAction) self.iface.removePluginMenu('Lat Lon Tools', self.toMGRSAction) self.iface.removePluginMenu('Lat Lon Tools', self.settingsAction) self.iface.removePluginMenu('Lat Lon Tools', self.helpAction) self.iface.removeDockWidget(self.zoomToDialog) self.iface.removeDockWidget(self.multiZoomDialog) self.zoomToDialog = None self.multiZoomDialog = None def startCapture(self): '''Set the focus of the copy coordinate tool and check it''' self.copyAction.setChecked(True) self.canvas.setMapTool(self.mapTool) def setShowMapTool(self): '''Set the focus of the external map tool and check it''' self.externMapAction.setChecked(True) self.canvas.setMapTool(self.showMapTool) def showZoomToDialog(self): '''Show the zoom to docked widget.''' self.zoomToDialog.show() def multiZoomTo(self): '''Display the Multi-zoom to dialog box''' self.multiZoomDialog.show() def toMGRS(self): '''Display the to MGRS dialog box''' self.toMGRSDialog.show() def MGRStoLayer(self): '''Display the to MGRS dialog box''' self.MGRStoLayerDialog.show() def settings(self): '''Show the settings dialog box''' self.settingsDialog.show() def help(self): '''Display a help page''' url = QUrl.fromLocalFile(os.path.dirname(__file__) + "/index.html").toString() webbrowser.open(url, new=2) def settingsChanged(self): # Settings may have changed so we need to make sure the zoomToDialog window is configured properly self.zoomToDialog.configure() def zoomTo(self, srcCrs, lat, lon): canvasCrs = self.canvas.mapSettings().destinationCrs() transform = QgsCoordinateTransform(srcCrs, canvasCrs) x, y = transform.transform(float(lon), float(lat)) rect = QgsRectangle(x, y, x, y) self.canvas.setExtent(rect) pt = QgsPoint(x, y) self.highlight(pt) self.canvas.refresh() return pt def highlight(self, point): currExt = self.canvas.extent() leftPt = QgsPoint(currExt.xMinimum(), point.y()) rightPt = QgsPoint(currExt.xMaximum(), point.y()) topPt = QgsPoint(point.x(), currExt.yMaximum()) bottomPt = QgsPoint(point.x(), currExt.yMinimum()) horizLine = QgsGeometry.fromPolyline([leftPt, rightPt]) vertLine = QgsGeometry.fromPolyline([topPt, bottomPt]) self.crossRb.reset(QgsWkbTypes.LineGeometry) self.crossRb.addGeometry(horizLine, None) self.crossRb.addGeometry(vertLine, None) QTimer.singleShot(700, self.resetRubberbands) def resetRubberbands(self): self.crossRb.reset()
class ShapeTools(object): def __init__(self, iface): self.iface = iface self.canvas = iface.mapCanvas() self.settingsDialog = None self.shapeDialog = None self.xyLineDialog = None self.geodesicDensifyDialog = None self.azDigitizerTool = None self.lineDigitizerTool = None self.previousLayer = None self.toolbar = self.iface.addToolBar('Shape Tools Toolbar') self.toolbar.setObjectName('ShapeToolsToolbar') self.provider = ShapeToolsProvider() def initGui(self): self.azDigitizerTool = AzDigitizerTool(self.iface) self.lineDigitizerTool = LineDigitizerTool(self.iface) # Initialize the create shape menu item icon = QIcon(os.path.dirname(__file__) + '/images/shapes.png') self.shapeAction = QAction(icon, tr('Create shapes'), self.iface.mainWindow()) self.shapeAction.setObjectName('stCreateShapes') self.shapeAction.triggered.connect(self.shapeTool) self.iface.addPluginToVectorMenu('Shape Tools', self.shapeAction) self.toolbar.addAction(self.shapeAction) # Initialize the XY to Line menu item icon = QIcon(os.path.dirname(__file__) + '/images/xyline.png') self.xyLineAction = QAction(icon, tr('XY to Line'), self.iface.mainWindow()) self.xyLineAction.setObjectName('stXYtoLine') self.xyLineAction.triggered.connect(self.xyLineTool) self.iface.addPluginToVectorMenu('Shape Tools', self.xyLineAction) self.toolbar.addAction(self.xyLineAction) # Initialize the Geodesic Densifier menu item icon = QIcon( os.path.dirname(__file__) + '/images/geodesicDensifier.png') self.geodesicDensifyAction = QAction(icon, tr('Geodesic shape densifier'), self.iface.mainWindow()) self.geodesicDensifyAction.setObjectName('stGeodesicDensifier') self.geodesicDensifyAction.triggered.connect(self.geodesicDensifyTool) self.iface.addPluginToVectorMenu('Shape Tools', self.geodesicDensifyAction) self.toolbar.addAction(self.geodesicDensifyAction) # Initialize the Geodesic line break menu item icon = QIcon(os.path.dirname(__file__) + '/images/idlbreak.png') self.geodesicLineBreakAction = QAction( icon, tr('Geodesic line break at -180,180'), self.iface.mainWindow()) self.geodesicLineBreakAction.setObjectName('stGeodesicLineBreak') self.geodesicLineBreakAction.triggered.connect( self.geodesicLineBreakTool) self.iface.addPluginToVectorMenu('Shape Tools', self.geodesicLineBreakAction) self.toolbar.addAction(self.geodesicLineBreakAction) # Initialize Geodesic Measure Tool self.geodesicMeasureTool = GeodesicMeasureTool(self.iface, self.iface.mainWindow()) icon = QIcon(os.path.dirname(__file__) + '/images/measure.png') self.measureAction = QAction(icon, tr('Geodesic measure tool'), self.iface.mainWindow()) self.measureAction.setObjectName('stGeodesicMeasureTool') self.measureAction.triggered.connect(self.measureTool) self.measureAction.setCheckable(True) self.iface.addPluginToVectorMenu('Shape Tools', self.measureAction) self.toolbar.addAction(self.measureAction) # Initialize Geodesic Measurement layer icon = QIcon(os.path.dirname(__file__) + '/images/measureLine.png') self.measureLayerAction = QAction(icon, tr('Geodesic measurement layer'), self.iface.mainWindow()) self.measureLayerAction.setObjectName('stGeodesicLineBreak') self.measureLayerAction.triggered.connect(self.measureLayerTool) self.iface.addPluginToVectorMenu('Shape Tools', self.measureLayerAction) self.toolbar.addAction(self.measureLayerAction) menu = QMenu() # Initialize Geodesic transformation tool icon = QIcon(os.path.dirname(__file__) + '/images/transformShape.png') self.transformationsAction = menu.addAction( icon, tr('Geodesic transformations'), self.transformTool) self.transformationsAction.setObjectName('stGeodesicTransformations') icon = QIcon(os.path.dirname(__file__) + '/images/flip.png') self.flipRotateAction = menu.addAction(icon, tr('Geodesic flip and rotate'), self.flipRotateTool) self.flipRotateAction.setObjectName('stGeodesicFlipRotate') icon = QIcon(os.path.dirname(__file__) + '/images/flipHorizontal.png') self.flipHorizontalAction = menu.addAction(icon, tr('Flip horizontal'), self.flipHorizontalTool) self.flipHorizontalAction.setObjectName('stGeodesicFlipHorizontal') self.flipHorizontalAction.setEnabled(False) icon = QIcon(os.path.dirname(__file__) + '/images/flipVertical.png') self.flipVerticalAction = menu.addAction(icon, tr('Flip vertical'), self.flipVerticalTool) self.flipVerticalAction.setObjectName('stGeodesicFlipVertical') self.flipVerticalAction.setEnabled(False) icon = QIcon(os.path.dirname(__file__) + '/images/rotate180.png') self.rotate180Action = menu.addAction(icon, tr('Rotate 180\xb0'), self.rotate180Tool) self.rotate180Action.setObjectName('stGeodesicRotate180') self.rotate180Action.setEnabled(False) icon = QIcon(os.path.dirname(__file__) + '/images/rotatecw.png') self.rotate90CWAction = menu.addAction(icon, tr('Rotate 90\xb0 CW'), self.rotate90CWTool) self.rotate90CWAction.setObjectName('stGeodesicRotate90CW') self.rotate90CWAction.setEnabled(False) icon = QIcon(os.path.dirname(__file__) + '/images/rotateccw.png') self.rotate90CCWAction = menu.addAction(icon, tr('Rotate 90\xb0 CCW'), self.rotate90CCWTool) self.rotate90CCWAction.setObjectName('stGeodesicRotate90CCW') self.rotate90CCWAction.setEnabled(False) self.transformsAction = QAction(icon, tr('Geodesic Transforms'), self.iface.mainWindow()) self.transformsAction.setMenu(menu) self.iface.addPluginToVectorMenu('Shape Tools', self.transformsAction) self.transformationButton = QToolButton() self.transformationButton.setMenu(menu) self.transformationButton.setDefaultAction(self.transformationsAction) self.transformationButton.setPopupMode(QToolButton.MenuButtonPopup) self.transformationButton.triggered.connect(self.toolButtonTriggered) self.tranformToolbar = self.toolbar.addWidget( self.transformationButton) # Initialize the Azimuth Distance Digitize function icon = QIcon(os.path.dirname(__file__) + '/images/dazdigitize.png') self.digitizeAction = QAction(icon, tr('Azimuth distance digitizer'), self.iface.mainWindow()) self.digitizeAction.setObjectName('stAzDistanceDigitizer') self.digitizeAction.triggered.connect(self.setShowAzDigitizerTool) self.digitizeAction.setCheckable(True) self.digitizeAction.setEnabled(False) self.iface.addPluginToVectorMenu(u'Shape Tools', self.digitizeAction) self.toolbar.addAction(self.digitizeAction) # Initialize the multi point azimuth Digitize function icon = QIcon(os.path.dirname(__file__) + '/images/linedigitize.png') self.lineDigitizeAction = QAction( icon, tr('Azimuth distance sequence digitizer'), self.iface.mainWindow()) self.lineDigitizeAction.setObjectName('stLineDigitizer') self.lineDigitizeAction.triggered.connect(self.setShowLineDigitizeTool) self.lineDigitizeAction.setCheckable(True) self.lineDigitizeAction.setEnabled(False) self.iface.addPluginToVectorMenu(u'Shape Tools', self.lineDigitizeAction) self.toolbar.addAction(self.lineDigitizeAction) # Settings icon = QIcon(os.path.dirname(__file__) + '/images/settings.png') self.settingsAction = QAction(icon, tr('Settings'), self.iface.mainWindow()) self.settingsAction.setObjectName('shapeToolsSettings') self.settingsAction.triggered.connect(self.settings) self.iface.addPluginToVectorMenu('Shape Tools', self.settingsAction) # Help icon = QIcon(os.path.dirname(__file__) + '/images/help.png') self.helpAction = QAction(icon, tr('Shape Tools help'), self.iface.mainWindow()) self.helpAction.setObjectName('shapeToolsHelp') self.helpAction.triggered.connect(self.help) self.iface.addPluginToVectorMenu('Shape Tools', self.helpAction) self.iface.currentLayerChanged.connect(self.currentLayerChanged) self.canvas.mapToolSet.connect(self.unsetTool) self.enableTools() # Add the processing provider QgsApplication.processingRegistry().addProvider(self.provider) def unsetTool(self, tool): try: if not isinstance(tool, GeodesicMeasureTool): self.measureAction.setChecked(False) self.geodesicMeasureTool.closeDialog() if not isinstance(tool, AzDigitizerTool): self.digitizeAction.setChecked(False) if not isinstance(tool, LineDigitizerTool): self.lineDigitizeAction.setChecked(False) except: pass def unload(self): self.canvas.unsetMapTool(self.azDigitizerTool) self.canvas.unsetMapTool(self.lineDigitizerTool) # remove from menu self.iface.removePluginVectorMenu('Shape Tools', self.shapeAction) self.iface.removePluginVectorMenu('Shape Tools', self.xyLineAction) self.iface.removePluginVectorMenu('Shape Tools', self.geodesicDensifyAction) self.iface.removePluginVectorMenu('Shape Tools', self.geodesicLineBreakAction) self.iface.removePluginVectorMenu('Shape Tools', self.measureAction) self.iface.removePluginVectorMenu('Shape Tools', self.measureLayerAction) self.iface.removePluginVectorMenu('Shape Tools', self.transformsAction) self.iface.removePluginVectorMenu('Shape Tools', self.digitizeAction) self.iface.removePluginVectorMenu('Shape Tools', self.lineDigitizeAction) self.iface.removePluginVectorMenu('Shape Tools', self.settingsAction) self.iface.removePluginVectorMenu('Shape Tools', self.helpAction) # Remove from toolbar self.iface.removeToolBarIcon(self.shapeAction) self.iface.removeToolBarIcon(self.xyLineAction) self.iface.removeToolBarIcon(self.geodesicDensifyAction) self.iface.removeToolBarIcon(self.geodesicLineBreakAction) self.iface.removeToolBarIcon(self.measureAction) self.iface.removeToolBarIcon(self.measureLayerAction) self.iface.removeToolBarIcon(self.transformationsAction) self.iface.removeToolBarIcon(self.digitizeAction) self.iface.removeToolBarIcon(self.lineDigitizeAction) self.iface.removeToolBarIcon(self.tranformToolbar) self.azDigitizerTool = None self.lineDigitizerTool = None # remove the toolbar del self.toolbar QgsApplication.processingRegistry().removeProvider(self.provider) def toolButtonTriggered(self, action): self.transformationButton.setDefaultAction(action) def shapeTool(self): if self.shapeDialog is None: self.shapeDialog = Vector2ShapeWidget(self.iface, self.iface.mainWindow()) self.shapeDialog.show() def setShowAzDigitizerTool(self): self.digitizeAction.setChecked(True) self.canvas.setMapTool(self.azDigitizerTool) def setShowLineDigitizeTool(self): self.lineDigitizeAction.setChecked(True) self.canvas.setMapTool(self.lineDigitizerTool) def xyLineTool(self): results = processing.execAlgorithmDialog('shapetools:xy2line', {}) def geodesicDensifyTool(self): results = processing.execAlgorithmDialog( 'shapetools:geodesicdensifier', {}) def geodesicLineBreakTool(self): results = processing.execAlgorithmDialog('shapetools:linebreak', {}) def measureTool(self): self.measureAction.setChecked(True) self.canvas.setMapTool(self.geodesicMeasureTool) def measureLayerTool(self): results = processing.execAlgorithmDialog('shapetools:measurelayer', {}) def transformTool(self): results = processing.execAlgorithmDialog( 'shapetools:geodesictransformations', {}) def flipRotateTool(self): results = processing.execAlgorithmDialog('shapetools:geodesicflip', {}) def flipHorizontalTool(self): layer = self.iface.activeLayer() flipLayer(self.iface, layer, 0) def flipVerticalTool(self): layer = self.iface.activeLayer() flipLayer(self.iface, layer, 1) def rotate180Tool(self): layer = self.iface.activeLayer() flipLayer(self.iface, layer, 2) def rotate90CWTool(self): layer = self.iface.activeLayer() flipLayer(self.iface, layer, 3) def rotate90CCWTool(self): layer = self.iface.activeLayer() flipLayer(self.iface, layer, 4) def settings(self): if self.settingsDialog is None: self.settingsDialog = SettingsWidget(self.iface, self.iface.mainWindow()) self.settingsDialog.show() def help(self): '''Display a help page''' url = QUrl.fromLocalFile(os.path.dirname(__file__) + '/index.html').toString() webbrowser.open(url, new=2) def currentLayerChanged(self): layer = self.iface.activeLayer() if self.previousLayer != None: try: self.previousLayer.editingStarted.disconnect( self.layerEditingChanged) except: pass try: self.previousLayer.editingStopped.disconnect( self.layerEditingChanged) except: pass self.previousLayer = None if layer != None: if isinstance(layer, QgsVectorLayer): layer.editingStarted.connect(self.layerEditingChanged) layer.editingStopped.connect(self.layerEditingChanged) self.previousLayer = layer self.enableTools() def layerEditingChanged(self): self.enableTools() def enableTools(self): self.digitizeAction.setEnabled(False) self.lineDigitizeAction.setEnabled(False) self.flipHorizontalAction.setEnabled(False) self.flipVerticalAction.setEnabled(False) self.rotate180Action.setEnabled(False) self.rotate90CWAction.setEnabled(False) self.rotate90CCWAction.setEnabled(False) layer = self.iface.activeLayer() if not layer or not layer.isValid() or ( layer.type() != QgsMapLayer.VectorLayer) or not layer.isEditable(): return wkbtype = layer.wkbType() geomtype = QgsWkbTypes.geometryType(wkbtype) self.lineDigitizeAction.setEnabled(True) if geomtype == QgsWkbTypes.PointGeometry or geomtype == QgsWkbTypes.LineGeometry: self.digitizeAction.setEnabled(True) if geomtype == QgsWkbTypes.LineGeometry or geomtype == QgsWkbTypes.PolygonGeometry: self.flipHorizontalAction.setEnabled(True) self.flipVerticalAction.setEnabled(True) self.rotate180Action.setEnabled(True) self.rotate90CWAction.setEnabled(True) self.rotate90CCWAction.setEnabled(True)
class LatLonTools: digitizerDialog = None toMGRSDialog = None MGRStoLayerDialog = None geom2FieldDialog = None def __init__(self, iface): self.iface = iface self.canvas = iface.mapCanvas() self.crossRb = QgsRubberBand(self.canvas, QgsWkbTypes.LineGeometry) self.crossRb.setColor(Qt.red) self.provider = LatLonToolsProvider() def initGui(self): '''Initialize Lot Lon Tools GUI.''' # Initialize the Settings Dialog box self.settingsDialog = SettingsWidget(self, self.iface, self.iface.mainWindow()) self.mapTool = CopyLatLonTool(self.settingsDialog, self.iface) self.showMapTool = ShowOnMapTool(self.settingsDialog, self.iface) # Add Interface for Coordinate Capturing icon = QIcon(os.path.dirname(__file__) + "/images/copyicon.png") self.copyAction = QAction(icon, "Copy Latitude, Longitude", self.iface.mainWindow()) self.copyAction.setObjectName('latLonToolsCopy') self.copyAction.triggered.connect(self.startCapture) self.copyAction.setCheckable(True) self.iface.addToolBarIcon(self.copyAction) self.iface.addPluginToMenu("Lat Lon Tools", self.copyAction) # Add Interface for Zoom to Coordinate icon = QIcon(os.path.dirname(__file__) + "/images/zoomicon.png") self.zoomToAction = QAction(icon, "Zoom To Latitude, Longitude", self.iface.mainWindow()) self.zoomToAction.setObjectName('latLonToolsZoom') self.zoomToAction.triggered.connect(self.showZoomToDialog) self.iface.addPluginToMenu('Lat Lon Tools', self.zoomToAction) self.zoomToDialog = ZoomToLatLon(self, self.iface, self.iface.mainWindow()) self.iface.addDockWidget(Qt.LeftDockWidgetArea, self.zoomToDialog) self.zoomToDialog.hide() # Add Interface for External Map icon = QIcon(os.path.dirname(__file__) + "/images/mapicon.png") self.externMapAction = QAction(icon, "Show in External Map", self.iface.mainWindow()) self.externMapAction.setObjectName('latLonToolsExternalMap') self.externMapAction.triggered.connect(self.setShowMapTool) self.externMapAction.setCheckable(True) self.iface.addToolBarIcon(self.externMapAction) self.iface.addPluginToMenu("Lat Lon Tools", self.externMapAction) # Add Interface for Multi point zoom icon = QIcon(os.path.dirname(__file__) + '/images/multizoom.png') self.multiZoomToAction = QAction(icon, "Multi-location Zoom", self.iface.mainWindow()) self.multiZoomToAction.setObjectName('latLonToolsMultiZoom') self.multiZoomToAction.triggered.connect(self.multiZoomTo) self.iface.addPluginToMenu('Lat Lon Tools', self.multiZoomToAction) self.multiZoomDialog = MultiZoomWidget(self, self.settingsDialog, self.iface.mainWindow()) self.multiZoomDialog.hide() self.multiZoomDialog.setFloating(True) # Add To MGRS conversion menu = QMenu() icon = QIcon(os.path.dirname(__file__) + '/images/geom2field.png') action = menu.addAction(icon, "Geometry to Field", self.geom2Field) action.setObjectName('latLonToolsGeom2Field') icon = QIcon(os.path.dirname(__file__) + '/images/mgrs2point.png') action = menu.addAction(icon, "MGRS to Geometry", self.MGRStoLayer) action.setObjectName('latLonToolsMGRS2Geom') icon = QIcon(os.path.dirname(__file__) + '/images/point2mgrs.png') action = menu.addAction(icon, "Geometry to MGRS", self.toMGRS) action.setObjectName('latLonToolsGeom2MGRS') self.toMGRSAction = QAction(icon, "Conversions", self.iface.mainWindow()) self.toMGRSAction.setMenu(menu) self.iface.addPluginToMenu('Lat Lon Tools', self.toMGRSAction) # Initialize the Settings Dialog Box settingsicon = QIcon(os.path.dirname(__file__) + '/images/settings.png') self.settingsAction = QAction(settingsicon, "Settings", self.iface.mainWindow()) self.settingsAction.setObjectName('latLonToolsSettings') self.settingsAction.triggered.connect(self.settings) self.iface.addPluginToMenu('Lat Lon Tools', self.settingsAction) # Help icon = QIcon(os.path.dirname(__file__) + '/images/help.png') self.helpAction = QAction(icon, "Help", self.iface.mainWindow()) self.helpAction.setObjectName('latLonToolsHelp') self.helpAction.triggered.connect(self.help) self.iface.addPluginToMenu('Lat Lon Tools', self.helpAction) # Add to Digitize Toolbar icon = QIcon(os.path.dirname(__file__) + '/images/latLonDigitize.png') self.digitizeAction = QAction(icon, "Lat Lon Digitize", self.iface.mainWindow()) self.digitizeAction.setObjectName('latLonToolsDigitize') self.digitizeAction.triggered.connect(self.digitizeClicked) self.digitizeAction.setEnabled(False) self.iface.digitizeToolBar().addAction(self.digitizeAction) self.iface.currentLayerChanged.connect(self.currentLayerChanged) self.canvas.mapToolSet.connect(self.unsetTool) self.enableDigitizeTool() # Add the processing provider QgsApplication.processingRegistry().addProvider(self.provider) def unsetTool(self, tool): '''Uncheck the Copy Lat Lon tool''' try: if not isinstance(tool, CopyLatLonTool): self.copyAction.setChecked(False) self.multiZoomDialog.stopCapture() self.mapTool.capture4326 = False if not isinstance(tool, ShowOnMapTool): self.externMapAction.setChecked(False) except: pass def unload(self): '''Unload LatLonTools from the QGIS interface''' self.zoomToDialog.removeMarker() self.multiZoomDialog.removeMarkers() self.canvas.unsetMapTool(self.mapTool) self.canvas.unsetMapTool(self.showMapTool) self.iface.removePluginMenu('Lat Lon Tools', self.copyAction) self.iface.removeToolBarIcon(self.copyAction) self.iface.removePluginMenu('Lat Lon Tools', self.externMapAction) self.iface.removeToolBarIcon(self.externMapAction) self.iface.removePluginMenu('Lat Lon Tools', self.zoomToAction) self.iface.removePluginMenu('Lat Lon Tools', self.multiZoomToAction) self.iface.removePluginMenu('Lat Lon Tools', self.toMGRSAction) self.iface.removePluginMenu('Lat Lon Tools', self.settingsAction) self.iface.removePluginMenu('Lat Lon Tools', self.helpAction) self.iface.removeDockWidget(self.zoomToDialog) self.iface.removeDockWidget(self.multiZoomDialog) self.geom2FieldDialog = None self.MGRStoLayerDialog = None self.toMGRSDialog = None self.zoomToDialog = None self.multiZoomDialog = None self.settingsDialog = None self.showMapTool = None self.mapTool = None self.iface.digitizeToolBar().removeAction(self.digitizeAction) self.digitizerDialog = None QgsApplication.processingRegistry().removeProvider(self.provider) def startCapture(self): '''Set the focus of the copy coordinate tool and check it''' self.copyAction.setChecked(True) self.canvas.setMapTool(self.mapTool) def setShowMapTool(self): '''Set the focus of the external map tool and check it''' self.externMapAction.setChecked(True) self.canvas.setMapTool(self.showMapTool) def showZoomToDialog(self): '''Show the zoom to docked widget.''' self.zoomToDialog.show() def multiZoomTo(self): '''Display the Multi-zoom to dialog box''' self.multiZoomDialog.show() def geom2Field(self): '''Convert layer geometry to a text string''' if self.geom2FieldDialog == None: from .geom2field import Geom2FieldWidget self.geom2FieldDialog = Geom2FieldWidget(self.iface, self.iface.mainWindow()) self.geom2FieldDialog.show() def toMGRS(self): '''Display the to MGRS dialog box''' results = processing.execAlgorithmDialog('latlontools:point2mgrs', {}) def MGRStoLayer(self): '''Display the to MGRS dialog box''' results = processing.execAlgorithmDialog('latlontools:mgrs2point', {}) def settings(self): '''Show the settings dialog box''' self.settingsDialog.show() def help(self): '''Display a help page''' url = QUrl.fromLocalFile(os.path.dirname(__file__) + "/index.html").toString() webbrowser.open(url, new=2) def settingsChanged(self): # Settings may have changed so we need to make sure the zoomToDialog window is configured properly self.zoomToDialog.configure() self.multiZoomDialog.settingsChanged() def zoomTo(self, srcCrs, lat, lon): canvasCrs = self.canvas.mapSettings().destinationCrs() transform = QgsCoordinateTransform(srcCrs, canvasCrs, QgsProject.instance()) x, y = transform.transform(float(lon), float(lat)) rect = QgsRectangle(x,y,x,y) self.canvas.setExtent(rect) pt = QgsPointXY(x,y) self.highlight(pt) self.canvas.refresh() return pt def highlight(self, point): currExt = self.canvas.extent() leftPt = QgsPoint(currExt.xMinimum(),point.y()) rightPt = QgsPoint(currExt.xMaximum(),point.y()) topPt = QgsPoint(point.x(),currExt.yMaximum()) bottomPt = QgsPoint(point.x(),currExt.yMinimum()) horizLine = QgsGeometry.fromPolyline( [ leftPt , rightPt ] ) vertLine = QgsGeometry.fromPolyline( [ topPt , bottomPt ] ) self.crossRb.reset(QgsWkbTypes.LineGeometry) self.crossRb.addGeometry(horizLine, None) self.crossRb.addGeometry(vertLine, None) QTimer.singleShot(700, self.resetRubberbands) def resetRubberbands(self): self.crossRb.reset() def digitizeClicked(self): if self.digitizerDialog == None: from .digitizer import DigitizerWidget self.digitizerDialog = DigitizerWidget(self, self.iface, self.iface.mainWindow()) self.digitizerDialog.show() def currentLayerChanged(self): layer = self.iface.activeLayer() if layer != None: try: layer.editingStarted.disconnect(self.layerEditingChanged) except: pass try: layer.editingStopped.disconnect(self.layerEditingChanged) except: pass if isinstance(layer, QgsVectorLayer): layer.editingStarted.connect(self.layerEditingChanged) layer.editingStopped.connect(self.layerEditingChanged) self.enableDigitizeTool() def layerEditingChanged(self): self.enableDigitizeTool() def enableDigitizeTool(self): self.digitizeAction.setEnabled(False) layer = self.iface.activeLayer() if layer != None and isinstance(layer, QgsVectorLayer) and (layer.wkbType() == QgsWkbTypes.Point) and layer.isEditable(): self.digitizeAction.setEnabled(True) else: if self.digitizerDialog != None: self.digitizerDialog.close()
class LatLonTools: digitizerDialog = None def __init__(self, iface): self.iface = iface self.canvas = iface.mapCanvas() self.crossRb = QgsRubberBand(self.canvas, QgsWkbTypes.LineGeometry) self.crossRb.setColor(Qt.red) self.provider = LatLonToolsProvider() self.toolbar = self.iface.addToolBar('Lat Lon Tools Toolbar') self.toolbar.setObjectName('LatLonToolsToolbar') def initGui(self): '''Initialize Lot Lon Tools GUI.''' # Initialize the Settings Dialog box self.settingsDialog = SettingsWidget(self, self.iface, self.iface.mainWindow()) self.mapTool = CopyLatLonTool(self.settingsDialog, self.iface) self.showMapTool = ShowOnMapTool(self.iface) # Add Interface for Coordinate Capturing icon = QIcon(os.path.dirname(__file__) + "/images/copyicon.png") self.copyAction = QAction(icon, "Copy Latitude, Longitude", self.iface.mainWindow()) self.copyAction.setObjectName('latLonToolsCopy') self.copyAction.triggered.connect(self.startCapture) self.copyAction.setCheckable(True) self.toolbar.addAction(self.copyAction) self.iface.addPluginToMenu("Lat Lon Tools", self.copyAction) # Add Interface for External Map icon = QIcon(os.path.dirname(__file__) + "/images/mapicon.png") self.externMapAction = QAction(icon, "Show in External Map", self.iface.mainWindow()) self.externMapAction.setObjectName('latLonToolsExternalMap') self.externMapAction.triggered.connect(self.setShowMapTool) self.externMapAction.setCheckable(True) self.toolbar.addAction(self.externMapAction) self.iface.addPluginToMenu("Lat Lon Tools", self.externMapAction) # Add Interface for Zoom to Coordinate icon = QIcon(os.path.dirname(__file__) + "/images/zoomicon.png") self.zoomToAction = QAction(icon, "Zoom To Latitude, Longitude", self.iface.mainWindow()) self.zoomToAction.setObjectName('latLonToolsZoom') self.zoomToAction.triggered.connect(self.showZoomToDialog) self.toolbar.addAction(self.zoomToAction) self.iface.addPluginToMenu('Lat Lon Tools', self.zoomToAction) self.zoomToDialog = ZoomToLatLon(self, self.iface, self.iface.mainWindow()) self.iface.addDockWidget(Qt.LeftDockWidgetArea, self.zoomToDialog) self.zoomToDialog.hide() # Add Interface for Multi point zoom icon = QIcon(os.path.dirname(__file__) + '/images/multizoom.png') self.multiZoomToAction = QAction(icon, "Multi-location Zoom", self.iface.mainWindow()) self.multiZoomToAction.setObjectName('latLonToolsMultiZoom') self.multiZoomToAction.triggered.connect(self.multiZoomTo) self.toolbar.addAction(self.multiZoomToAction) self.iface.addPluginToMenu('Lat Lon Tools', self.multiZoomToAction) self.multiZoomDialog = MultiZoomWidget(self, self.settingsDialog, self.iface.mainWindow()) self.multiZoomDialog.hide() self.multiZoomDialog.setFloating(True) # Create the conversions menu menu = QMenu() icon = QIcon(os.path.dirname(__file__) + '/images/field2geom.png') action = menu.addAction(icon, "Fields to point layer", self.field2geom) action.setObjectName('latLonToolsField2Geom') icon = QIcon(os.path.dirname(__file__) + '/images/geom2field.png') action = menu.addAction(icon, "Point layer to fields", self.geom2Field) action.setObjectName('latLonToolsGeom2Field') icon = QIcon(os.path.dirname(__file__) + '/images/pluscodes.png') action = menu.addAction(icon, "Plus Codes to point layer", self.PlusCodestoLayer) action.setObjectName('latLonToolsPlusCodes2Geom') action = menu.addAction(icon, "Point layer to Plus Codes", self.toPlusCodes) action.setObjectName('latLonToolsGeom2PlusCodes') icon = QIcon(os.path.dirname(__file__) + '/images/mgrs2point.png') action = menu.addAction(icon, "MGRS to point layer", self.MGRStoLayer) action.setObjectName('latLonToolsMGRS2Geom') icon = QIcon(os.path.dirname(__file__) + '/images/point2mgrs.png') action = menu.addAction(icon, "Point layer to MGRS", self.toMGRS) action.setObjectName('latLonToolsGeom2MGRS') self.conversionsAction = QAction(icon, "Conversions", self.iface.mainWindow()) self.conversionsAction.setMenu(menu) self.iface.addPluginToMenu('Lat Lon Tools', self.conversionsAction) # Add to Digitize Toolbar icon = QIcon(os.path.dirname(__file__) + '/images/latLonDigitize.png') self.digitizeAction = QAction(icon, "Lat Lon Digitize", self.iface.mainWindow()) self.digitizeAction.setObjectName('latLonToolsDigitize') self.digitizeAction.triggered.connect(self.digitizeClicked) self.digitizeAction.setEnabled(False) self.toolbar.addAction(self.digitizeAction) self.iface.addPluginToMenu('Lat Lon Tools', self.digitizeAction) # Add Interface for copying the canvas extent icon = QIcon(os.path.dirname(__file__) + "/images/copycanvas.png") self.copyCanvasAction = QAction(icon, "Copy Canvas Bounding Box", self.iface.mainWindow()) self.copyCanvasAction.setObjectName('latLonToolsCopyCanvas') self.copyCanvasAction.triggered.connect(self.copyCanvas) self.toolbar.addAction(self.copyCanvasAction) self.iface.addPluginToMenu("Lat Lon Tools", self.copyCanvasAction) # Initialize the Settings Dialog Box settingsicon = QIcon(os.path.dirname(__file__) + '/images/settings.png') self.settingsAction = QAction(settingsicon, "Settings", self.iface.mainWindow()) self.settingsAction.setObjectName('latLonToolsSettings') self.settingsAction.triggered.connect(self.settings) self.iface.addPluginToMenu('Lat Lon Tools', self.settingsAction) # Help icon = QIcon(os.path.dirname(__file__) + '/images/help.png') self.helpAction = QAction(icon, "Help", self.iface.mainWindow()) self.helpAction.setObjectName('latLonToolsHelp') self.helpAction.triggered.connect(self.help) self.iface.addPluginToMenu('Lat Lon Tools', self.helpAction) self.iface.currentLayerChanged.connect(self.currentLayerChanged) self.canvas.mapToolSet.connect(self.unsetTool) self.enableDigitizeTool() # Add the processing provider QgsApplication.processingRegistry().addProvider(self.provider) def unsetTool(self, tool): '''Uncheck the Copy Lat Lon tool''' try: if not isinstance(tool, CopyLatLonTool): self.copyAction.setChecked(False) self.multiZoomDialog.stopCapture() self.mapTool.capture4326 = False if not isinstance(tool, ShowOnMapTool): self.externMapAction.setChecked(False) except: pass def unload(self): '''Unload LatLonTools from the QGIS interface''' self.zoomToDialog.removeMarker() self.multiZoomDialog.removeMarkers() self.canvas.unsetMapTool(self.mapTool) self.canvas.unsetMapTool(self.showMapTool) self.iface.removePluginMenu('Lat Lon Tools', self.copyAction) self.iface.removePluginMenu('Lat Lon Tools', self.copyCanvasAction) self.iface.removePluginMenu('Lat Lon Tools', self.externMapAction) self.iface.removePluginMenu('Lat Lon Tools', self.zoomToAction) self.iface.removePluginMenu('Lat Lon Tools', self.multiZoomToAction) self.iface.removePluginMenu('Lat Lon Tools', self.conversionsAction) self.iface.removePluginMenu('Lat Lon Tools', self.settingsAction) self.iface.removePluginMenu('Lat Lon Tools', self.helpAction) self.iface.removePluginMenu('Lat Lon Tools', self.digitizeAction) self.iface.removeDockWidget(self.zoomToDialog) self.iface.removeDockWidget(self.multiZoomDialog) # Remove Toolbar Icons self.iface.removeToolBarIcon(self.copyAction) self.iface.removeToolBarIcon(self.copyCanvasAction) self.iface.removeToolBarIcon(self.zoomToAction) self.iface.removeToolBarIcon(self.externMapAction) self.iface.removeToolBarIcon(self.multiZoomToAction) self.iface.removeToolBarIcon(self.digitizeAction) del self.toolbar self.zoomToDialog = None self.multiZoomDialog = None self.settingsDialog = None self.showMapTool = None self.mapTool = None self.digitizerDialog = None QgsApplication.processingRegistry().removeProvider(self.provider) def startCapture(self): '''Set the focus of the copy coordinate tool and check it''' self.copyAction.setChecked(True) self.canvas.setMapTool(self.mapTool) def copyCanvas(self): extent = self.iface.mapCanvas().extent() canvasCrs = self.canvas.mapSettings().destinationCrs() if settings.bBoxCrs == 0 and canvasCrs != epsg4326: transform = QgsCoordinateTransform(canvasCrs, epsg4326, QgsProject.instance()) p1x, p1y = transform.transform(float(extent.xMinimum()), float(extent.yMinimum())) p2x, p2y = transform.transform(float(extent.xMaximum()), float(extent.yMaximum())) extent.set(p1x, p1y, p2x, p2y) delim = settings.bBoxDelimiter prefix = settings.bBoxPrefix suffix = settings.bBoxSuffix precision = settings.bBoxDigits outStr = '' minX = extent.xMinimum() minY = extent.yMinimum() maxX = extent.xMaximum() maxY = extent.yMaximum() if settings.bBoxFormat == 0: # minX,minY,maxX,maxY - using the delimiter outStr = '{:.{prec}f}{}{:.{prec}f}{}{:.{prec}f}{}{:.{prec}f}'.format( minX, delim, minY, delim, maxX, delim, maxY, prec=precision) elif settings.bBoxFormat == 1: # minX,maxX,minY,maxY - Using the selected delimiter' outStr = '{:.{prec}f}{}{:.{prec}f}{}{:.{prec}f}{}{:.{prec}f}'.format( minX, delim, maxX, delim, minY, delim, maxY, prec=precision) elif settings.bBoxFormat == 2: # x1 y1,x2 y2,x3 y3,x4 y4,x1 y1 - Polygon format outStr = '{:.{prec}f} {:.{prec}f},{:.{prec}f} {:.{prec}f},{:.{prec}f} {:.{prec}f},{:.{prec}f} {:.{prec}f},{:.{prec}f} {:.{prec}f}'.format( minX, minY, minX, maxY, maxX, maxY, maxX, minY, minX, minY, prec=precision) elif settings.bBoxFormat == 3: # x1,y1 x2,y2 x3,y3 x4,y4 x1,y1 - Polygon format outStr = '{:.{prec}f},{:.{prec}f} {:.{prec}f},{:.{prec}f} {:.{prec}f},{:.{prec}f} {:.{prec}f},{:.{prec}f} {:.{prec}f},{:.{prec}f}'.format( minX, minY, minX, maxY, maxX, maxY, maxX, minY, minX, minY, prec=precision) elif settings.bBoxFormat == 4: # WKT Polygon outStr = extent.asWktPolygon() elif settings.bBoxFormat == 5: # bbox: [minX, minY, maxX, maxY] - MapProxy outStr = 'bbox: [{}, {}, {}, {}]'.format( minX, minY, maxX, maxY) elif settings.bBoxFormat == 6: # bbox: [minX, minY, maxX, maxY] - MapProxy outStr = 'bbox={},{},{},{}'.format( minX, minY, maxX, maxY) outStr = '{}{}{}'.format(prefix, outStr, suffix) clipboard = QApplication.clipboard() clipboard.setText(outStr) self.iface.messageBar().pushMessage("", "'{}' copied to the clipboard".format(outStr), level=Qgis.Info, duration=4) def setShowMapTool(self): '''Set the focus of the external map tool and check it''' self.externMapAction.setChecked(True) self.canvas.setMapTool(self.showMapTool) def showZoomToDialog(self): '''Show the zoom to docked widget.''' self.zoomToDialog.show() def multiZoomTo(self): '''Display the Multi-zoom to dialog box''' self.multiZoomDialog.show() def field2geom(self): '''Convert layer containing a point x & y coordinate to a new point layer''' results = processing.execAlgorithmDialog('latlontools:field2geom', {}) def geom2Field(self): '''Convert layer geometry to a text string''' results = processing.execAlgorithmDialog('latlontools:geom2field', {}) def toMGRS(self): '''Display the to MGRS dialog box''' results = processing.execAlgorithmDialog('latlontools:point2mgrs', {}) def MGRStoLayer(self): '''Display the to MGRS dialog box''' results = processing.execAlgorithmDialog('latlontools:mgrs2point', {}) def toPlusCodes(self): results = processing.execAlgorithmDialog('latlontools:point2pluscodes', {}) def PlusCodestoLayer(self): results = processing.execAlgorithmDialog('latlontools:pluscodes2point', {}) def settings(self): '''Show the settings dialog box''' self.settingsDialog.show() def help(self): '''Display a help page''' url = QUrl.fromLocalFile(os.path.dirname(__file__) + "/index.html").toString() webbrowser.open(url, new=2) def settingsChanged(self): # Settings may have changed so we need to make sure the zoomToDialog window is configured properly self.zoomToDialog.configure() self.multiZoomDialog.settingsChanged() def zoomTo(self, srcCrs, lat, lon): canvasCrs = self.canvas.mapSettings().destinationCrs() transform = QgsCoordinateTransform(srcCrs, canvasCrs, QgsProject.instance()) x, y = transform.transform(float(lon), float(lat)) rect = QgsRectangle(x, y, x, y) self.canvas.setExtent(rect) pt = QgsPointXY(x, y) self.highlight(pt) self.canvas.refresh() return pt def highlight(self, point): currExt = self.canvas.extent() leftPt = QgsPoint(currExt.xMinimum(), point.y()) rightPt = QgsPoint(currExt.xMaximum(), point.y()) topPt = QgsPoint(point.x(), currExt.yMaximum()) bottomPt = QgsPoint(point.x(), currExt.yMinimum()) horizLine = QgsGeometry.fromPolyline( [ leftPt , rightPt ] ) vertLine = QgsGeometry.fromPolyline( [ topPt , bottomPt ] ) self.crossRb.reset(QgsWkbTypes.LineGeometry) self.crossRb.addGeometry(horizLine, None) self.crossRb.addGeometry(vertLine, None) QTimer.singleShot(700, self.resetRubberbands) def resetRubberbands(self): self.crossRb.reset() def digitizeClicked(self): if self.digitizerDialog == None: from .digitizer import DigitizerWidget self.digitizerDialog = DigitizerWidget(self, self.iface, self.iface.mainWindow()) self.digitizerDialog.show() def currentLayerChanged(self): layer = self.iface.activeLayer() if layer != None: try: layer.editingStarted.disconnect(self.layerEditingChanged) except: pass try: layer.editingStopped.disconnect(self.layerEditingChanged) except: pass if isinstance(layer, QgsVectorLayer): layer.editingStarted.connect(self.layerEditingChanged) layer.editingStopped.connect(self.layerEditingChanged) self.enableDigitizeTool() def layerEditingChanged(self): self.enableDigitizeTool() def enableDigitizeTool(self): self.digitizeAction.setEnabled(False) layer = self.iface.activeLayer() if layer != None and isinstance(layer, QgsVectorLayer) and (layer.geometryType() == QgsWkbTypes.PointGeometry) and layer.isEditable(): self.digitizeAction.setEnabled(True) else: if self.digitizerDialog != None: self.digitizerDialog.close()