From 387057a1b885f499ff2c5ce2ac2f8d79202da14f Mon Sep 17 00:00:00 2001 From: Etienne Trimaille Date: Thu, 31 Aug 2017 16:07:02 +0200 Subject: [PATCH] add CRS description in the layer_property expression --- resources/function_help/json/layer_property | 2 +- src/core/expression/qgsexpressionfunction.cpp | 2 ++ tests/src/core/testqgsexpression.cpp | 2 ++ 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/resources/function_help/json/layer_property b/resources/function_help/json/layer_property index 470c33db79b..f6c33d482fe 100644 --- a/resources/function_help/json/layer_property +++ b/resources/function_help/json/layer_property @@ -4,7 +4,7 @@ "description": "Returns a matching layer property or metadata value.", "arguments": [ {"arg":"layer", "description":"a string, representing either a layer name or layer ID"}, - {"arg":"property", "description":"a string corresponding to the property to return. Valid options are:
"} + {"arg":"property", "description":"a string corresponding to the property to return. Valid options are:
"} ], "examples": [ { "expression":"layer_property('streets','title')", "returns":"'Basemap Streets'"}, diff --git a/src/core/expression/qgsexpressionfunction.cpp b/src/core/expression/qgsexpressionfunction.cpp index 97ba905bd45..769e6f9883c 100644 --- a/src/core/expression/qgsexpressionfunction.cpp +++ b/src/core/expression/qgsexpressionfunction.cpp @@ -3515,6 +3515,8 @@ static QVariant fcnGetLayerProperty( const QVariantList &values, const QgsExpres return layer->crs().authid(); else if ( QString::compare( layerProperty, QStringLiteral( "crs_definition" ), Qt::CaseInsensitive ) == 0 ) return layer->crs().toProj4(); + else if ( QString::compare( layerProperty, QStringLiteral( "crs_description" ), Qt::CaseInsensitive ) == 0 ) + return layer->crs().description(); else if ( QString::compare( layerProperty, QStringLiteral( "extent" ), Qt::CaseInsensitive ) == 0 ) { QgsGeometry extentGeom = QgsGeometry::fromRect( layer->extent() ); diff --git a/tests/src/core/testqgsexpression.cpp b/tests/src/core/testqgsexpression.cpp index 921b4574035..dcf804be299 100644 --- a/tests/src/core/testqgsexpression.cpp +++ b/tests/src/core/testqgsexpression.cpp @@ -1149,6 +1149,8 @@ class TestQgsExpression: public QObject QTest::newRow( "layer_property min_scale" ) << QStringLiteral( "layer_property('%1','min_scale')" ).arg( mPointsLayer->name() ) << false << QVariant( mPointsLayer->minimumScale() ); QTest::newRow( "layer_property max_scale" ) << QStringLiteral( "layer_property('%1','max_scale')" ).arg( mPointsLayer->name() ) << false << QVariant( mPointsLayer->maximumScale() ); QTest::newRow( "layer_property crs" ) << QStringLiteral( "layer_property('%1','crs')" ).arg( mPointsLayer->name() ) << false << QVariant( "EPSG:4326" ); + QTest::newRow( "layer_property crs_description" ) << QStringLiteral( "layer_property('%1','crs_description')" ).arg( mPointsLayer->name() ) << false << QVariant( "WGS 84" ); + QTest::newRow( "layer_property crs_definition" ) << QStringLiteral( "layer_property('%1','crs_definition')" ).arg( mPointsLayer->name() ) << false << QVariant( "+proj=longlat +datum=WGS84 +no_defs" ); QTest::newRow( "layer_property extent" ) << QStringLiteral( "geom_to_wkt(layer_property('%1','extent'))" ).arg( mPointsLayer->name() ) << false << QVariant( "Polygon ((-118.88888889 22.80020704, -83.33333333 22.80020704, -83.33333333 46.87198068, -118.88888889 46.87198068, -118.88888889 22.80020704))" ); QTest::newRow( "layer_property type" ) << QStringLiteral( "layer_property('%1','type')" ).arg( mPointsLayer->name() ) << false << QVariant( "Vector" ); QTest::newRow( "layer_property storage_type" ) << QStringLiteral( "layer_property('%1','storage_type')" ).arg( mPointsLayer->name() ) << false << QVariant( "ESRI Shapefile" );