-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
33c003b
commit 0eb6a1a
Showing
7 changed files
with
112 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
from qgis.PyQt.QtCore import Qt, pyqtSignal | ||
from qgis.PyQt.QtGui import QColor | ||
from qgis.PyQt.QtCore import pyqtSlot | ||
from qgis.core import QgsCoordinateTransform, QgsPointXY, QgsProject, QgsSettings | ||
from qgis.gui import QgsMapToolEmitPoint, QgsVertexMarker | ||
from .util import epsg4326 | ||
|
||
class CaptureCoordinate(QgsMapToolEmitPoint): | ||
'''Class to interact with the map canvas to capture the coordinate | ||
when the mouse button is pressed.''' | ||
capturePoint = pyqtSignal(QgsPointXY) | ||
captureStopped = pyqtSignal() | ||
|
||
def __init__(self, canvas): | ||
QgsMapToolEmitPoint.__init__(self, canvas) | ||
self.canvas = canvas | ||
self.vertex = None | ||
|
||
def activate(self): | ||
'''When activated set the cursor to a crosshair.''' | ||
self.canvas.setCursor(Qt.CrossCursor) | ||
self.snapcolor = QgsSettings().value( "/qgis/digitizing/snap_color" , QColor( Qt.magenta ) ) | ||
|
||
def deactivate(self): | ||
self.removeVertexMarker() | ||
self.captureStopped.emit() | ||
|
||
def snappoint(self, qpoint): | ||
match = self.canvas.snappingUtils().snapToMap(qpoint) | ||
if match.isValid(): | ||
if self.vertex is None: | ||
self.vertex = QgsVertexMarker(self.canvas) | ||
self.vertex.setIconSize(12) | ||
self.vertex.setPenWidth(2) | ||
self.vertex.setColor(self.snapcolor) | ||
self.vertex.setIconType(QgsVertexMarker.ICON_BOX) | ||
self.vertex.setCenter(match.point()) | ||
return (match.point()) # Returns QgsPointXY | ||
else: | ||
self.removeVertexMarker() | ||
return self.toMapCoordinates(qpoint) # QPoint input, returns QgsPointXY | ||
|
||
def canvasMoveEvent(self, event): | ||
'''Capture the coordinate as the user moves the mouse over | ||
the canvas.''' | ||
self.snappoint(event.originalPixelPoint()) # input is QPoint | ||
|
||
def canvasReleaseEvent(self, event): | ||
'''Capture the coordinate when the mouse button has been released, | ||
format it, and copy it to the clipboard. pt is QgsPointXY''' | ||
pt = self.snappoint(event.originalPixelPoint()) | ||
self.removeVertexMarker() | ||
|
||
try: | ||
canvasCRS = self.canvas.mapSettings().destinationCrs() | ||
transform = QgsCoordinateTransform(canvasCRS, epsg4326, QgsProject.instance()) | ||
pt4326 = transform.transform(pt.x(), pt.y()) | ||
self.capturePoint.emit(pt4326) | ||
except Exception as e: | ||
pass | ||
|
||
def removeVertexMarker(self): | ||
if self.vertex is not None: | ||
self.canvas.scene().removeItem(self.vertex) | ||
self.vertex = None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
[general] | ||
name=Lat Lon Tools | ||
qgisMinimumVersion=3.0 | ||
qgisMinimumVersion=3.2 | ||
description=Tools to capture and zoom to coordinates using decimal, DMS, WKT, GeoJSON, MGRS, UTM, Geohash, and Plus Codes formats. Provides external map support, point digitizing tools, and coordinate conversion tools. | ||
version=3.3.12 | ||
version=3.3.13 | ||
author=C Hamilton | ||
[email protected] | ||
about= | ||
|
@@ -27,6 +27,7 @@ icon=images/copyicon.png | |
experimental=False | ||
deprecated=False | ||
changelog= | ||
3.3.13 - Fixed tool interactions | ||
3.3.12 - Made coordinate conversion dialog box dockable & added zoom to button. | ||
3.3.11 - Fix bug | ||
3.3.10 - Added 'degree minute' capture and to coordinate conversion dialog box. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters