class LatLonTools:
    def __init__(self, iface):
        self.iface = iface

    def initGui(self):
        self.settingsDialog = SettingsWidget(self.iface, self.iface.mainWindow())
        self.mapTool = CopyLatLonTool(self.settingsDialog, self.iface)

        icon = QIcon(":/plugins/latlontools/copyicon.png")
        self.copyAction = QAction(icon, "Copy Latitude, Longitude",
            self.iface.mainWindow())
        self.copyAction.triggered.connect(self.setTool)
        self.copyAction.setCheckable(True)
        self.iface.addToolBarIcon(self.copyAction)
        self.iface.addPluginToMenu("Lat Lon Tools", self.copyAction)

        zoomicon = QIcon(':/plugins/latlontools/zoomicon.png')
        self.zoomToAction = QAction(zoomicon, "Zoom To Latitude, Longitude", 
                    self.iface.mainWindow())
        self.zoomToAction.triggered.connect(self.zoomTo)
        self.iface.addPluginToMenu('Lat Lon Tools', self.zoomToAction)
        
        
        self.iface.mapCanvas().mapToolSet.connect(self.unsetTool)

        
        self.dockwidget = ZoomToLatLon(self.iface,
                    self.iface.mainWindow())
        self.iface.addDockWidget(Qt.LeftDockWidgetArea, self.dockwidget)
        self.dockwidget.hide()
        
        # Initialize the Settings Dialog Box
        settingsicon = QIcon(':/plugins/latlontools/settings.png')
        self.settingsAction = QAction(settingsicon, "Settings", 
                    self.iface.mainWindow())
        self.settingsAction.triggered.connect(self.settings)
        self.iface.addPluginToMenu('Lat Lon Tools', self.settingsAction)
        
    def unsetTool(self, tool):
        try:
            if not isinstance(tool, CopyLatLonTool):
                self.copyAction.setChecked(False)
        except:
            pass
 

    def unload(self):
        self.iface.mapCanvas().unsetMapTool(self.mapTool)
        self.iface.removePluginMenu('Lat Lon Tools', self.copyAction)
        self.iface.removeToolBarIcon(self.copyAction)
        self.iface.removePluginMenu('Lat Lon Tools', self.zoomToAction)
        self.iface.removePluginMenu('Lat Lon Tools', self.settingsAction)
        self.iface.removeDockWidget(self.dockwidget)
        self.dockwidget = None

    def setTool(self):
        self.copyAction.setChecked(True)
        self.iface.mapCanvas().setMapTool(self.mapTool)

    def zoomTo(self):
        self.dockwidget.show()
    
    def settings(self):
        self.settingsDialog.show()
class LatLonTools:
    def __init__(self, iface):
        self.iface = iface
        self.canvas = iface.mapCanvas()
        self.crossRb = QgsRubberBand(self.canvas, QGis.Line)
        self.crossRb.setColor(Qt.red)

    def initGui(self):
        '''Initialize Lot Lon Tools GUI.'''
        # Initialize the Settings Dialog box
        self.settingsDialog = SettingsWidget(self.iface, self.iface.mainWindow())
        self.multiZoomDialog = MultiZoomWidget(self, self.settingsDialog, self.iface.mainWindow())
        self.mapTool = CopyLatLonTool(self.settingsDialog, self.iface)
        
        # Add Interface for Coordinate Capturing
        icon = QIcon(":/plugins/latlontools/copyicon.png")
        self.copyAction = QAction(icon, "Copy Latitude, Longitude",
            self.iface.mainWindow())
        self.copyAction.triggered.connect(self.setTool)
        self.copyAction.setCheckable(True)
        self.iface.addToolBarIcon(self.copyAction)
        self.iface.addPluginToMenu("Lat Lon Tools", self.copyAction)

        # Add Interface for Zoom to Coordinate
        zoomicon = QIcon(':/plugins/latlontools/zoomicon.png')
        self.zoomToAction = QAction(zoomicon, "Zoom To Latitude, Longitude", 
                    self.iface.mainWindow())
        self.zoomToAction.triggered.connect(self.zoomTo)
        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 Multi point zoom
        zoomicon = QIcon(':/plugins/latlontools/multizoom.png')
        self.multiZoomToAction = QAction(zoomicon, "Multi-location Zoom", 
                    self.iface.mainWindow())
        self.multiZoomToAction.triggered.connect(self.multiZoomTo)
        self.iface.addPluginToMenu('Lat Lon Tools', self.multiZoomToAction)
        
        
        # Initialize the Settings Dialog Box
        settingsicon = QIcon(':/plugins/latlontools/settings.png')
        self.settingsAction = QAction(settingsicon, "Settings", 
                    self.iface.mainWindow())
        self.settingsAction.triggered.connect(self.settings)
        self.iface.addPluginToMenu('Lat Lon Tools', self.settingsAction)
        
    def unsetTool(self, tool):
        '''Uncheck the Copy Lat Lon tool'''
        try:
            if not isinstance(tool, CopyLatLonTool):
                self.copyAction.setChecked(False)
        except:
            pass

    def unload(self):
        '''Unload LatLonTools from the QGIS interface'''
        self.canvas.unsetMapTool(self.mapTool)
        self.iface.removePluginMenu('Lat Lon Tools', self.copyAction)
        self.iface.removeToolBarIcon(self.copyAction)
        self.iface.removePluginMenu('Lat Lon Tools', self.zoomToAction)
        self.iface.removePluginMenu('Lat Lon Tools', self.multiZoomToAction)
        self.iface.removePluginMenu('Lat Lon Tools', self.settingsAction)
        self.iface.removeDockWidget(self.zoomToDialog)
        self.zoomToDialog = None

    def setTool(self):
        '''Set the focus of the copy coordinate tool and check it'''
        self.copyAction.setChecked(True)
        self.canvas.setMapTool(self.mapTool)

    def zoomTo(self):
        '''Show the zoom to docked widget.'''
        self.zoomToDialog.show()

    def multiZoomTo(self):
        '''Display the Multi-zoom to dialog box'''
        self.multiZoomDialog.show()
    
    def settings(self):
        '''Show the settings dialog box'''
        self.settingsDialog.show()
 
    def zoomToLatLon(self, lat, lon):
        canvasCrs = self.canvas.mapRenderer().destinationCrs()
        epsg4326 = QgsCoordinateReferenceSystem("EPSG:4326")
        transform4326 = QgsCoordinateTransform(epsg4326, canvasCrs)
        x, y = transform4326.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()
        
    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(QGis.Line)
        self.crossRb.addGeometry(horizLine, None)
        self.crossRb.addGeometry(vertLine, None)
        
        QTimer.singleShot(700, self.resetRubberbands)
        
    def resetRubberbands(self):
        self.crossRb.reset()
예제 #3
0
class LatLonTools:
    def __init__(self, iface):
        self.iface = iface

    def initGui(self):
        self.settingsDialog = SettingsWidget(self.iface,
                                             self.iface.mainWindow())
        self.mapTool = CopyLatLonTool(self.settingsDialog, self.iface)

        icon = QIcon(":/plugins/latlontools/copyicon.png")
        self.copyAction = QAction(icon, "Copy Latitude, Longitude",
                                  self.iface.mainWindow())
        self.copyAction.triggered.connect(self.setTool)
        self.copyAction.setCheckable(True)
        self.iface.addToolBarIcon(self.copyAction)
        self.iface.addPluginToMenu("Lat Lon Tools", self.copyAction)

        zoomicon = QIcon(':/plugins/latlontools/zoomicon.png')
        self.zoomToAction = QAction(zoomicon, "Zoom To Latitude, Longitude",
                                    self.iface.mainWindow())
        self.zoomToAction.triggered.connect(self.zoomTo)
        self.iface.addPluginToMenu('Lat Lon Tools', self.zoomToAction)

        self.iface.mapCanvas().mapToolSet.connect(self.unsetTool)

        self.dockwidget = ZoomToLatLon(self.iface, self.iface.mainWindow())
        self.iface.addDockWidget(Qt.LeftDockWidgetArea, self.dockwidget)
        self.dockwidget.hide()

        # Initialize the Settings Dialog Box
        settingsicon = QIcon(':/plugins/latlontools/settings.png')
        self.settingsAction = QAction(settingsicon, "Settings",
                                      self.iface.mainWindow())
        self.settingsAction.triggered.connect(self.settings)
        self.iface.addPluginToMenu('Lat Lon Tools', self.settingsAction)

    def unsetTool(self, tool):
        try:
            if not isinstance(tool, CopyLatLonTool):
                self.copyAction.setChecked(False)
        except:
            pass

    def unload(self):
        self.iface.mapCanvas().unsetMapTool(self.mapTool)
        self.iface.removePluginMenu('Lat Lon Tools', self.copyAction)
        self.iface.removeToolBarIcon(self.copyAction)
        self.iface.removePluginMenu('Lat Lon Tools', self.zoomToAction)
        self.iface.removePluginMenu('Lat Lon Tools', self.settingsAction)
        self.iface.removeDockWidget(self.dockwidget)
        self.dockwidget = None

    def setTool(self):
        self.copyAction.setChecked(True)
        self.iface.mapCanvas().setMapTool(self.mapTool)

    def zoomTo(self):
        self.dockwidget.show()

    def settings(self):
        self.settingsDialog.show()
class LatLonTools:
    def __init__(self, iface):
        self.iface = iface
        self.canvas = iface.mapCanvas()
        self.crossRb = QgsRubberBand(self.canvas, QGis.Line)
        self.crossRb.setColor(Qt.red)

    def initGui(self):
        '''Initialize Lot Lon Tools GUI.'''
        # Initialize the Settings Dialog box
        self.settingsDialog = SettingsWidget(self.iface,
                                             self.iface.mainWindow())
        self.multiZoomDialog = MultiZoomWidget(self, self.settingsDialog,
                                               self.iface.mainWindow())
        self.mapTool = CopyLatLonTool(self.settingsDialog, self.iface)

        # Add Interface for Coordinate Capturing
        icon = QIcon(":/plugins/latlontools/copyicon.png")
        self.copyAction = QAction(icon, "Copy Latitude, Longitude",
                                  self.iface.mainWindow())
        self.copyAction.triggered.connect(self.setTool)
        self.copyAction.setCheckable(True)
        self.iface.addToolBarIcon(self.copyAction)
        self.iface.addPluginToMenu("Lat Lon Tools", self.copyAction)

        # Add Interface for Zoom to Coordinate
        zoomicon = QIcon(':/plugins/latlontools/zoomicon.png')
        self.zoomToAction = QAction(zoomicon, "Zoom To Latitude, Longitude",
                                    self.iface.mainWindow())
        self.zoomToAction.triggered.connect(self.zoomTo)
        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 Multi point zoom
        zoomicon = QIcon(':/plugins/latlontools/multizoom.png')
        self.multiZoomToAction = QAction(zoomicon, "Multi-location Zoom",
                                         self.iface.mainWindow())
        self.multiZoomToAction.triggered.connect(self.multiZoomTo)
        self.iface.addPluginToMenu('Lat Lon Tools', self.multiZoomToAction)

        # Initialize the Settings Dialog Box
        settingsicon = QIcon(':/plugins/latlontools/settings.png')
        self.settingsAction = QAction(settingsicon, "Settings",
                                      self.iface.mainWindow())
        self.settingsAction.triggered.connect(self.settings)
        self.iface.addPluginToMenu('Lat Lon Tools', self.settingsAction)

    def unsetTool(self, tool):
        '''Uncheck the Copy Lat Lon tool'''
        try:
            if not isinstance(tool, CopyLatLonTool):
                self.copyAction.setChecked(False)
        except:
            pass

    def unload(self):
        '''Unload LatLonTools from the QGIS interface'''
        self.canvas.unsetMapTool(self.mapTool)
        self.iface.removePluginMenu('Lat Lon Tools', self.copyAction)
        self.iface.removeToolBarIcon(self.copyAction)
        self.iface.removePluginMenu('Lat Lon Tools', self.zoomToAction)
        self.iface.removePluginMenu('Lat Lon Tools', self.multiZoomToAction)
        self.iface.removePluginMenu('Lat Lon Tools', self.settingsAction)
        self.iface.removeDockWidget(self.zoomToDialog)
        self.zoomToDialog = None

    def setTool(self):
        '''Set the focus of the copy coordinate tool and check it'''
        self.copyAction.setChecked(True)
        self.canvas.setMapTool(self.mapTool)

    def zoomTo(self):
        '''Show the zoom to docked widget.'''
        self.zoomToDialog.show()

    def multiZoomTo(self):
        '''Display the Multi-zoom to dialog box'''
        self.multiZoomDialog.show()

    def settings(self):
        '''Show the settings dialog box'''
        self.settingsDialog.show()

    def zoomToLatLon(self, lat, lon):
        canvasCrs = self.canvas.mapRenderer().destinationCrs()
        epsg4326 = QgsCoordinateReferenceSystem("EPSG:4326")
        transform4326 = QgsCoordinateTransform(epsg4326, canvasCrs)
        x, y = transform4326.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()

    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(QGis.Line)
        self.crossRb.addGeometry(horizLine, None)
        self.crossRb.addGeometry(vertLine, None)

        QTimer.singleShot(700, self.resetRubberbands)

    def resetRubberbands(self):
        self.crossRb.reset()
예제 #5
0
class ShapeTools:
    def __init__(self, iface):
        self.iface = iface

    def initGui(self):
        self.settingsDialog = SettingsWidget(self.iface,
                                             self.iface.mainWindow())
        self.shapeDialog = Vector2ShapeWidget(self.iface,
                                              self.iface.mainWindow(),
                                              self.settingsDialog)
        self.xyLineDialog = XYToLineWidget(self.iface, self.iface.mainWindow(),
                                           self.settingsDialog)

        # Initialize the create shape Dialog Box
        icon = QIcon(os.path.dirname(__file__) + '/images/shapes.png')
        self.shapeAction = QAction(icon, u'Create Shapes',
                                   self.iface.mainWindow())
        self.shapeAction.triggered.connect(self.shapeTool)
        self.iface.addPluginToVectorMenu(u'Shape Tools', self.shapeAction)

        # Initialize the XY to Line Dialog Box
        icon = QIcon(os.path.dirname(__file__) + '/images/xyline.png')
        self.xyLineAction = QAction(icon, u'XY to Line',
                                    self.iface.mainWindow())
        self.xyLineAction.triggered.connect(self.xyLineTool)
        self.iface.addPluginToVectorMenu(u'Shape Tools', self.xyLineAction)

        # Settings
        icon = QIcon(os.path.dirname(__file__) + '/images/settings.png')
        self.settingsAction = QAction(icon, u'Settings',
                                      self.iface.mainWindow())
        self.settingsAction.triggered.connect(self.settings)
        self.iface.addPluginToVectorMenu(u'Shape Tools', self.settingsAction)

        # Help
        icon = QIcon(os.path.dirname(__file__) + '/images/help.png')
        self.helpAction = QAction(icon, u'Shape Tools Help',
                                  self.iface.mainWindow())
        self.helpAction.triggered.connect(self.help)
        self.iface.addPluginToVectorMenu(u'Shape Tools', self.helpAction)

    def unload(self):
        self.iface.removePluginVectorMenu(u'Shape Tools', self.shapeAction)
        self.iface.removePluginVectorMenu(u'Shape Tools', self.xyLineAction)
        self.iface.removePluginVectorMenu(u'Shape Tools', self.settingsAction)
        self.iface.removePluginVectorMenu(u'Shape Tools', self.helpAction)

    def shapeTool(self):
        self.shapeDialog.show()

    def xyLineTool(self):
        self.xyLineDialog.show()

    def settings(self):
        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)