Sometimes, you may want to display a different coordinate system for the mouse coordinates in the status bar than what the source data is. With this recipe, you can set a different coordinate system without changing the data coordinate reference system or the CRS for the map.
Download the zipped shapefile and unzip it to your qgis_data/ms
directory from the following:
https://geospatialpython.googlecode.com/files/MSCities_Geo.zip
We will load our layer, establish a message in the status bar, create a special event listener to transform the map coordinates at the mouse's location to our alternate CRS, and then connect the map signal for the mouse's map coordinates to our listener function. To do this, we need to perform the following steps:
from PyQt4.QtCore import *
pth = "/qgis_data/ms/MSCities_Geo_Pts.shp" lyr = QgsVectorLayer(pth, "Cities", "ogr")
QgsMapLayerRegistry.instance().addMapLayer(lyr)
msg = "Alternate CRS ( x: %s, y: %s )"
iface.mainWindow().statusBar().showMessage(msg % ("--", "--"))
def listen_xyCoordinates(point): crsSrc = iface.mapCanvas().mapRenderer().destinationCrs() crsDest = QgsCoordinateReferenceSystem(3815) xform = QgsCoordinateTransform(crsSrc, crsDest) xpoint = xform.transform(point) iface.mainWindow().statusBar().showMessage(msg % (xpoint.x(), xpoint.y()))
QObject.connect(iface.mapCanvas(), SIGNAL("xyCoordinates(const QgsPoint &)"), listen_xyCoordinates)