Skip to content

Commit f471043

Browse files
committed
Enhancements to copy different geospatial extents to the clipboard
1 parent 61e1304 commit f471043

18 files changed

+1564
-294
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
PLUGINNAME = latlontools
22
PLUGINS = "$(HOME)"/AppData/Roaming/QGIS/QGIS3/profiles/default/python/plugins/$(PLUGINNAME)
3-
PY_FILES = latLonTools.py __init__.py copyLatLonTool.py captureCoordinate.py zoomToLatLon.py settings.py multizoom.py mgrs.py showOnMapTool.py mapProviders.py tomgrs.py mgrstogeom.py digitizer.py util.py geom2field.py field2geom.py olc.py provider.py pluscodes.py utm.py coordinateConverter.py geohash.py maidenhead.py latLonFunctions.py
3+
PY_FILES = latLonTools.py __init__.py copyLatLonTool.py captureCoordinate.py zoomToLatLon.py settings.py multizoom.py mgrs.py showOnMapTool.py mapProviders.py tomgrs.py mgrstogeom.py digitizer.py util.py geom2field.py field2geom.py olc.py provider.py pluscodes.py utm.py coordinateConverter.py geohash.py maidenhead.py latLonFunctions.py captureExtent.py
44
EXTRAS = metadata.txt
55

66
deploy:

captureExtent.py

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
from qgis.PyQt.QtCore import Qt
2+
from qgis.PyQt.QtWidgets import QApplication
3+
from qgis.core import Qgis, QgsCoordinateTransform, QgsCoordinateReferenceSystem, QgsProject
4+
from qgis.gui import QgsMapToolExtent
5+
# import traceback
6+
from .util import epsg4326
7+
from .settings import settings, CopyExtent
8+
9+
def getExtentString(bbox, src_crs, dst_crs):
10+
if src_crs != dst_crs:
11+
transform = QgsCoordinateTransform(src_crs, dst_crs, QgsProject.instance())
12+
bbox = transform.transformBoundingBox(bbox)
13+
delim = settings.bBoxDelimiter
14+
prefix = settings.bBoxPrefix
15+
suffix = settings.bBoxSuffix
16+
precision = settings.bBoxDigits
17+
outStr = ''
18+
minX = bbox.xMinimum()
19+
minY = bbox.yMinimum()
20+
maxX = bbox.xMaximum()
21+
maxY = bbox.yMaximum()
22+
if settings.bBoxFormat == CopyExtent.WSEN: # minX,minY,maxX,maxY (W,S,E,N)
23+
outStr = '{:.{prec}f}{}{:.{prec}f}{}{:.{prec}f}{}{:.{prec}f}'.format(
24+
minX, delim, minY, delim, maxX, delim, maxY, prec=precision)
25+
elif settings.bBoxFormat == CopyExtent.WESN: # minX,maxX,minY,maxY (W,E,S,N)
26+
outStr = '{:.{prec}f}{}{:.{prec}f}{}{:.{prec}f}{}{:.{prec}f}'.format(
27+
minX, delim, maxX, delim, minY, delim, maxY, prec=precision)
28+
elif settings.bBoxFormat == CopyExtent.SWNE: # minY,minX,maxY,maxX (S,W,N,E)
29+
outStr = '{:.{prec}f}{}{:.{prec}f}{}{:.{prec}f}{}{:.{prec}f}'.format(
30+
minY, delim, minX, delim, maxY, delim, maxX, prec=precision)
31+
elif settings.bBoxFormat == CopyExtent.Poly1: # x1 y1,x2 y2,x3 y3,x4 y4,x1 y1 - Polygon format
32+
outStr = '{:.{prec}f} {:.{prec}f},{:.{prec}f} {:.{prec}f},{:.{prec}f} {:.{prec}f},{:.{prec}f} {:.{prec}f},{:.{prec}f} {:.{prec}f}'.format(
33+
minX, minY, minX, maxY, maxX, maxY, maxX, minY, minX, minY, prec=precision)
34+
elif settings.bBoxFormat == CopyExtent.Poly2: # x1,y1 x2,y2 x3,y3 x4,y4 x1,y1 - Polygon format
35+
outStr = '{:.{prec}f},{:.{prec}f} {:.{prec}f},{:.{prec}f} {:.{prec}f},{:.{prec}f} {:.{prec}f},{:.{prec}f} {:.{prec}f},{:.{prec}f}'.format(
36+
minX, minY, minX, maxY, maxX, maxY, maxX, minY, minX, minY, prec=precision)
37+
elif settings.bBoxFormat == CopyExtent.PolyWkt: # WKT Polygon
38+
outStr = bbox.asWktPolygon()
39+
elif settings.bBoxFormat == CopyExtent.MapProxy: # bbox: [minX, minY, maxX, maxY] - MapProxy
40+
outStr = 'bbox: [{}, {}, {}, {}]'.format(
41+
minX, minY, maxX, maxY)
42+
elif settings.bBoxFormat == CopyExtent.GeoServer: # bbox=minX,minY,maxX,maxY - GeoServer
43+
outStr = 'bbox={},{},{},{}'.format(
44+
minX, minY, maxX, maxY)
45+
outStr = '{}{}{}'.format(prefix, outStr, suffix)
46+
return(outStr)
47+
48+
class CaptureExtentTool(QgsMapToolExtent):
49+
def __init__(self, iface, parent):
50+
self.iface = iface
51+
self.canvas = iface.mapCanvas()
52+
QgsMapToolExtent.__init__(self, self.canvas)
53+
self.extentChanged.connect(self.getExtent)
54+
55+
def activate(self):
56+
'''When activated set the cursor to a crosshair.'''
57+
self.canvas.setCursor(Qt.CrossCursor)
58+
59+
def deactivate(self):
60+
QgsMapToolExtent.deactivate(self)
61+
action = self.action()
62+
if action:
63+
action.setChecked(False)
64+
65+
def getExtent(self, bbox):
66+
if bbox.isNull():
67+
return
68+
canvasCRS = self.canvas.mapSettings().destinationCrs()
69+
if settings.bBoxCrs == 0:
70+
dstCRS = epsg4326
71+
else:
72+
dstCRS = canvasCRS
73+
74+
outStr = getExtentString(bbox, canvasCRS, dstCRS)
75+
76+
clipboard = QApplication.clipboard()
77+
clipboard.setText(outStr)
78+
self.iface.messageBar().pushMessage("", "'{}' copied to the clipboard".format(outStr), level=Qgis.Info, duration=4)

doc/menu.jpg

9.38 KB
Loading

doc/menu2.jpg

19.2 KB
Loading

doc/toolbar.jpg

7.97 KB
Loading

images/copycanvas.png

37 Bytes
Loading

images/copyextent.png

1.4 KB
Loading

images/copylayerextent.png

1.3 KB
Loading

images/copyselectedlayerextent.png

1.19 KB
Loading

index.html

+13-4
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ <h1>Lat Lon Tools Plugin</h1>
4040
<p><strong><em>Lat Lon Tools</em></strong> makes it easy to capture, zoom to coordinates, convert coordinates in text fields into new point layers, export point geometry into text fields, and interact with other on-line mapping tools. It adds MGRS, Standard UTM, Geohash, and Plus Code (Open Location Code) coordinate support to QGIS. When working with <strong>Google Earth</strong>, <strong>Google Maps</strong> or other on-line mapping tools, coordinates are specified in the order of 'Latitude, Longitude'. By default <strong><em>Lat Lon Tools</em></strong> uses the standard Google Map format, but is very flexible and can use virtually any projection and coordinate format for input and output. The following tools are available in <strong><em>Lat Lon Tools</em></strong>.</p>
4141
<div style="text-align:center"><img src="doc/menu.jpg" alt="Lat Lon Tools Plugin"></div>
4242

43+
<p>Here are the expanded <strong><em>Copy Extents to Clipboard</em></strong> menu items.</p>
44+
<div style="text-align:center"><img src="doc/menu2.jpg" alt="Lat Lon Tools Plugin"></div>
45+
4346
<p>Some of the functions can be accessed from the <strong><em>Lat Lon Tools</em></strong> toolbar. If for some reason the toolbar is missing, select the menu item <strong><em>View-&gt;Toolbars</em></strong> and make sure <strong><em>Lat Lon Tools Toolbar</em></strong> is enabled. The conversion algorithms can be run from the QGIS Processing Toolbox.</p>
4447
<div style="text-align:center"><img src="doc/toolbar.jpg" alt="Lat Lon Tools toolbar"></div>
4548

@@ -93,6 +96,15 @@ <h1>Lat Lon Tools Plugin</h1>
9396
</ul>
9497
</li>
9598
<li>
99+
<p><strong><em>Copy Extents to Clipboard</em></strong> - There are four tools used to copy a bounding box extent to the clipboard. The bounding box format is determined in settings dialog. The output CRS for the bounding box extent is either that of the QGIS project or EPSG:4326. The four copy extent tools are:</p>
100+
<ul>
101+
<li><img src="images/copycanvas.png" alt="Copy canvas bounding box"> - Copy the canvas bounding box extent to the clipboard.</li>
102+
<li><img src="images/copyextent.png" alt="Copy selected area to an extent"> - Interactively select a region on the map to extract its bounding box extent and copy it to the clipboard.</li>
103+
<li><img src="images/copylayerextent.png" alt="Copy selected area to an extent"> - Copy the selected layer's extent. In some vector layers, this value may be estimated and not exact depending on how the layer was imported into QGIS.</li>
104+
<li><img src="images/copyselectedlayerextent.png" alt="Copy selected area to an extent"> - Copy the bounding box extent of selected features in a vector layer. If no features are selected then nothing will be copied. If the layer is not a vector layer, then the bounding box extent of the layer will be copied. In some vector layers, the bounding box extent may be estimated and not exact depending on how the layer was imported into QGIS.</li>
105+
</ul>
106+
</li>
107+
<li>
96108
<p><img src="doc/conversion.jpg" alt="Coordinate Conversion"> <strong><em>Coordinate Conversion Tool</em></strong> - This dialog provides a way to either type in a coordinate or grab a coordinate from the map and convert it to a number of different formats.</p>
97109
<p><div style="text-align:center"><img src="doc/coordinateConversion.jpg" alt="Coordinate Conversion"></div></p>
98110
<p>Type in a coordinate in any one of the formats listed and then press the enter button or click on the green check box next to the coordinate field and all the other coordinates will be populated. Here are the functions of the following icons:</p>
@@ -155,9 +167,6 @@ <h1>Lat Lon Tools Plugin</h1>
155167
<p><div style="text-align:center"><img src="doc/geom2pluscodes.jpg" alt="Point layer to Plus Codes"></div></p>
156168
</li>
157169
<li>
158-
<p><img src="images/copycanvas.png" alt="Copy canvas bounding box"> <strong><em>Copy Canvas Bounding Box</em></strong> - Copy the canvas bounding box to the clipboard using one of the formats in settings.</p>
159-
</li>
160-
<li>
161170
<p><img src="doc/settings.png" alt="Settings"> <strong><em>Settings</em></strong> - Displays the settings dialog box (see below).</p>
162171
</li>
163172
<li><img src="images/help.png" alt="Help"> <strong><em>Help</em></strong> - Displays this help page.</li>
@@ -307,7 +316,7 @@ <h3>Multi-location Zoom Settings</h3>
307316
<ul>
308317
<li><strong><em>Number of extra data fields</em></strong> - Besides <em>Latitude</em>, <em>Longitude</em>, and <em>Label</em>, the user can add up to 10 additional data fields which are labeled as <em>Data1</em>, <em>Data2</em>, ... <em>Data10</em>. By default this is set to 0.</li>
309318
</ul>
310-
<h3>BBox Capture Settings</h3>
319+
<h3>BBox (Bounding Box Extent) Capture Settings</h3>
311320
<div style="text-align:center"><img src="doc/settings5.jpg" alt="BBOX Capture Settings"></div>
312321

313322
<p>These are the settings for the bounding box capture to clipboard tool.</p>

0 commit comments

Comments
 (0)