TransWikia.com

Copying coordinates under mouse to clipboard in QGIS

Geographic Information Systems Asked by mefistotelis on July 1, 2021

I need a way to quickly copy coordinates under mouse to paste them to external program (3D reconstruction software I use for making maps from photos).

I see the coordinates within status bar at bottom of the screen; my hack of getting what I want right now is to:

  1. Place mouse over the place you want coordinates of
  2. Press Alt-tab to switch to another full-screen application
  3. Now you can move the mouse without changing coordinates in QGIS; get mouse to the bottom of the screen, outside of map area
  4. Alt-tab back to QGIS
  5. Copy the coordinates from the fields at bottom, be very careful not to get the mouse over the map or the coordinates will get updated

So this works, but is a bit annoying. Is there a better way?
When I try to google this, I’m getting articles on "Coordinate Capture" Plugin. But it doesn’t seem to be present in current versions of QGIS.

3 Answers

For QGIS versions lower than QGIS 3.14

Previously in QGIS it was possible by means of the "Coordinate Capture" Plugin (firstly it was a Plugin, then it became a Core Plugin). There are some threads on this particular topic: Coordinate Capture in QGIS 3.0 and How to turn the QGIS "Coordinate capture" plugin on?.

plugin_gui

For QGIS versions QGIS 3.14 and higher

Nowadays the functionality of this Plugin has been added as a map toolkit in QGIS 3.14, see this issue on the GitHub for more details.

So, simply RMC the map canvas > Copy Coordinate..., see the image below

result

and get a pair of your coordinates as 9.115780774,48.813284425.

Correct answer by Taras on July 1, 2021

If you need to transform the coordinates (like swapping X and Y, using a specific CRS, using a specific format etc), or if you need to capture an extent, you can use the lat lon tools plugin.

Once the tool is selected, each time you (left) click on the map the mouse coordinates is copied to the clipboard.

Answered by JGH on July 1, 2021

Use this script in QGIS Python Editor. It copies the coordinates under the cursor to clipboard, then you can paste them to other application.

class CopyCoordinatesTool(QgsMapTool):
    def __init__(self, iface):
        QgsMapTool.__init__(self, iface.mapCanvas())
        self.canvas = iface.mapCanvas()
    
    def activate(self):
        self.canvas.setCursor(Qt.ArrowCursor)

    def canvasMoveEvent(self, e):
        crs = self.canvas.mapSettings().destinationCrs()
        x = e.pos().x()
        y = e.pos().y()
        p = self.canvas.getCoordinateTransform().toMapCoordinates(x, y)
        
        c = QApplication.clipboard()
        c.setText(f"{p.x()}, {p.y()}n")

map_tool = CopyCoordinatesTool(iface)
iface.mapCanvas().setMapTool(map_tool)

Demo:

enter image description here

Answered by Kadir Şahbaz on July 1, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP