Adding coordinate system to layout in QGIS composer?

Answer for QGIS 3.x:

A) For the CRS name of a specific layer use this:

Add this script to your custom functioneditor:

from qgis.core import *
from qgis.gui import *

@qgsfunction(args='auto', group='Custom')
def get_crs(layer_name, feature, parent):
    return QgsProject.instance().mapLayersByName(layer_name)[0].crs().description()

enter image description here

and then get the crs name in expression editor with

get_crs(@layer_name)

enter image description here

Or use the expression layer_property( @layer_name, 'crs_description') as suggested by @etrimaille

B) For the CRS name of your project (for example projection in your print layout) use this:

Add this script to your custom functioneditor:

from qgis.core import *
from qgis.gui import *

@qgsfunction(args='auto', group='Custom')
def get_projectcrs(project_crs, feature, parent):
    return QgsCoordinateReferenceSystem(project_crs).description()

enter image description here

and then get the crs name in expression editor with:

 get_projectcrs(@project_crs) 

enter image description here

Of course you can also type in e.g. 'EPSG:4326' manually or use another function than @project_crs which returns an EPSG-code. E.g. get_projectcrs('EPSG:3006')

Notes:

Also take a look at https://qgis.org/api/api_break.html for more information about changes in QGIS 3.x


This answer was provided and accepted prior to the release of QGIS 3.0.

To get the Authority ID (i.e. "EPSG:4326"):

  • You can simply use the expression [% layer_property( 'your_layer_name_or_id', 'crs' ) %]

If you want to get the textual description of the CRS (i.e. "WGS84"):

  • AFAIK, you must create a custom function. To do this, go to "Insert an expression", and type the following function in the Function Editor tab.

Code:

from qgis.core import *
from qgis.gui import *

@qgsfunction(args='auto', group='Custom')
def get_crs(layer_name, feature, parent):
    return QgsMapLayerRegistry.instance().mapLayersByName(layer_name)[0].crs().description()
  • Click on "Load"
  • In the Expression tab, type get_crs( 'your_layer_name' )