Skip to content
Permalink
Browse files

[FEATURE] Expression variables for project CRS

Adds @project_crs and @project_crs_definition variables
for retrieving the current project CRS
  • Loading branch information
nyalldawson committed Nov 22, 2016
1 parent 271e67e commit 188033a6afc298864860ba94a3f150dd5e23f86d
Showing with 5 additions and 0 deletions.
  1. +2 −0 src/core/qgsexpression.cpp
  2. +3 −0 src/core/qgsexpressioncontext.cpp
@@ -5712,6 +5712,8 @@ void QgsExpression::initVariableHelp()
gVariableHelpTexts.insert( QStringLiteral( "project_path" ), QCoreApplication::translate( "variable_help", "Full path (including file name) of current project." ) );
gVariableHelpTexts.insert( QStringLiteral( "project_folder" ), QCoreApplication::translate( "variable_help", "Folder for current project." ) );
gVariableHelpTexts.insert( QStringLiteral( "project_filename" ), QCoreApplication::translate( "variable_help", "Filename of current project." ) );
gVariableHelpTexts.insert( QStringLiteral( "project_crs" ), QCoreApplication::translate( "variable_help", "Coordinate reference system of project (eg 'EPSG:4326')." ) );
gVariableHelpTexts.insert( QStringLiteral( "project_crs_definition" ), QCoreApplication::translate( "variable_help", "Coordinate reference system of project (full definition)." ) );

//layer variables
gVariableHelpTexts.insert( QStringLiteral( "layer_name" ), QCoreApplication::translate( "variable_help", "Name of current layer." ) );
@@ -644,6 +644,9 @@ QgsExpressionContextScope* QgsExpressionContextUtils::projectScope()
scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "project_path" ), project->fileInfo().filePath(), true ) );
scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "project_folder" ), project->fileInfo().dir().path(), true ) );
scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "project_filename" ), project->fileInfo().fileName(), true ) );
QgsCoordinateReferenceSystem projectCrs = project->crs();
scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "project_crs" ), projectCrs.authid(), true ) );
scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "project_crs_definition" ), projectCrs.toProj4(), true ) );

scope->addFunction( QStringLiteral( "project_color" ), new GetNamedProjectColor() );
return scope;

1 comment on commit 188033a

@m-kuhn

This comment has been minimized.

Copy link
Member

@m-kuhn m-kuhn commented on 188033a Nov 22, 2016

I was thinking, would it make sense to also expose the canvas crs (thinking about @ahuarte47 work on multi canvas or maybe different maps in the print composer)

Please sign in to comment.
You can’t perform that action at this time.