6

I'm want to display the current project projection in a QGIS layout.

Right now I can get QGIS to display the current EPSG number like below:

Current Solution

But what I want to do is get QGIS layout to print the ESPG name as well like below with an expression:

What I want

8

I think you will need a custom function to do this, the following seems to work though I haven't tested it extensively.

from qgis.core import *
from qgis.gui import *
from qgis.utils import iface

@qgsfunction(args='auto', group='Custom')
def getCrsDescription(feature, parent):
    """
    Returns the description text of the project CRS
    <h2>Example usage:</h2>
    <ul>
      <li>getCrsDescription() -> WGS 84</li>
      <li>getCrsDescription() -> OSGB 1936 / British National Grid</li>
    </ul>
    """
    return iface.mapCanvas().mapSettings().destinationCrs().description()
4
3

This behavior will be improved in an upcoming release of QGIS due to the below fix by Nyall Dawson and Alex Royas: https://github.com/qgis/QGIS/commit/a10bb387a767c21b27d345138227286ac2bd7ce2

New expression variables:

project_units

  • Unit of the project's CRS

project_crs_description

  • Name of the coordinate reference system of the project

project_crs_acronym

  • Acronym of the coordinate reference system of the project

project_crs_ellipsoid

  • Acronym of the ellipsoid of the coordinate reference system of the project

project_crs_proj4

  • Proj4 definition of the coordinate reference system of the project

project_crs_wkt

  • WKT definition of the coordinate reference system of the project

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.