I would like to know if there is a way to add a dynamic coordinate system field into a QGIS composer layout.
I can use an expression to add many items such as document name, file path, etc but I can;t seem to figure out how to add the coordinate system?
Answer
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' )
No comments:
Post a Comment