Skip to content

Commit 188033a

Browse files
committedNov 22, 2016
[FEATURE] Expression variables for project CRS
Adds @project_crs and @project_crs_definition variables for retrieving the current project CRS
1 parent 271e67e commit 188033a

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed
 

‎src/core/qgsexpression.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5712,6 +5712,8 @@ void QgsExpression::initVariableHelp()
57125712
gVariableHelpTexts.insert( QStringLiteral( "project_path" ), QCoreApplication::translate( "variable_help", "Full path (including file name) of current project." ) );
57135713
gVariableHelpTexts.insert( QStringLiteral( "project_folder" ), QCoreApplication::translate( "variable_help", "Folder for current project." ) );
57145714
gVariableHelpTexts.insert( QStringLiteral( "project_filename" ), QCoreApplication::translate( "variable_help", "Filename of current project." ) );
5715+
gVariableHelpTexts.insert( QStringLiteral( "project_crs" ), QCoreApplication::translate( "variable_help", "Coordinate reference system of project (eg 'EPSG:4326')." ) );
5716+
gVariableHelpTexts.insert( QStringLiteral( "project_crs_definition" ), QCoreApplication::translate( "variable_help", "Coordinate reference system of project (full definition)." ) );
57155717

57165718
//layer variables
57175719
gVariableHelpTexts.insert( QStringLiteral( "layer_name" ), QCoreApplication::translate( "variable_help", "Name of current layer." ) );

‎src/core/qgsexpressioncontext.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,9 @@ QgsExpressionContextScope* QgsExpressionContextUtils::projectScope()
644644
scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "project_path" ), project->fileInfo().filePath(), true ) );
645645
scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "project_folder" ), project->fileInfo().dir().path(), true ) );
646646
scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "project_filename" ), project->fileInfo().fileName(), true ) );
647+
QgsCoordinateReferenceSystem projectCrs = project->crs();
648+
scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "project_crs" ), projectCrs.authid(), true ) );
649+
scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "project_crs_definition" ), projectCrs.toProj4(), true ) );
647650

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

1 commit comments

Comments
 (1)

m-kuhn commented on Nov 22, 2016

@m-kuhn
Member

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.