Skip to content
Permalink
Browse files

Show full CRS WKT for custom CRS in layer properties

Fixes #33862
  • Loading branch information
nyalldawson committed Feb 3, 2020
1 parent db40d88 commit 19d58bda08c202b29020a3e9c485fac80350fc79
@@ -648,7 +648,14 @@ Returns the descriptive name of the CRS, e.g., "WGS 84" or "GDA 94 / Vicgrid94".
.. seealso:: :py:func:`userFriendlyIdentifier`
%End

QString userFriendlyIdentifier( bool shortString = false ) const;
enum IdentifierType
{
ShortString,
MediumString,
FullString,
};

QString userFriendlyIdentifier( IdentifierType type = MediumString ) const;
%Docstring
Returns a user friendly identifier for the CRS.

@@ -659,8 +666,6 @@ of the CRS.
In most cases this is the best method to use when showing a friendly identifier for the CRS to a
user.

If ``shortString`` is ``True`` than an abbreviated identifier will be returned.

.. seealso:: :py:func:`description`

.. versionadded:: 3.10.3
@@ -70,8 +70,8 @@ void QgsAppMissingGridHandler::onMissingRequiredGrid( const QgsCoordinateReferen
if ( !shouldWarnAboutPair( sourceCrs, destinationCrs ) )
return;

const QString shortMessage = tr( "No transform available between %1 and %2" ).arg( sourceCrs.userFriendlyIdentifier( true ),
destinationCrs.userFriendlyIdentifier( true ) );
const QString shortMessage = tr( "No transform available between %1 and %2" ).arg( sourceCrs.userFriendlyIdentifier( QgsCoordinateReferenceSystem::ShortString ),
destinationCrs.userFriendlyIdentifier( QgsCoordinateReferenceSystem::ShortString ) );

QString downloadMessage;
const QString gridName = grid.shortName;
@@ -117,8 +117,8 @@ void QgsAppMissingGridHandler::onMissingPreferredGrid( const QgsCoordinateRefere
if ( !shouldWarnAboutPair( sourceCrs, destinationCrs ) )
return;

const QString shortMessage = tr( "Cannot use preferred transform between %1 and %2" ).arg( sourceCrs.userFriendlyIdentifier( true ),
destinationCrs.userFriendlyIdentifier( true ) );
const QString shortMessage = tr( "Cannot use preferred transform between %1 and %2" ).arg( sourceCrs.userFriendlyIdentifier( QgsCoordinateReferenceSystem::ShortString ),
destinationCrs.userFriendlyIdentifier( QgsCoordinateReferenceSystem::ShortString ) );

QString gridMessage;
QString downloadMessage;
@@ -185,7 +185,7 @@ void QgsAppMissingGridHandler::onCoordinateOperationCreationError( const QgsCoor
if ( !shouldWarnAboutPairForCurrentProject( sourceCrs, destinationCrs ) )
return;

const QString shortMessage = tr( "No transform available between %1 and %2" ).arg( sourceCrs.userFriendlyIdentifier( true ), destinationCrs.userFriendlyIdentifier( true ) );
const QString shortMessage = tr( "No transform available between %1 and %2" ).arg( sourceCrs.userFriendlyIdentifier( QgsCoordinateReferenceSystem::ShortString ), destinationCrs.userFriendlyIdentifier( QgsCoordinateReferenceSystem::ShortString ) );
const QString longMessage = tr( "<p>No transform is available between <i>%1</i> and <i>%2</i>.</p><p style=\"color: red\">%3</p>" ).arg( sourceCrs.userFriendlyIdentifier(), destinationCrs.userFriendlyIdentifier(), error );

QgsMessageBar *bar = QgisApp::instance()->messageBar();
@@ -209,8 +209,8 @@ void QgsAppMissingGridHandler::onMissingGridUsedByContextHandler( const QgsCoord
if ( !shouldWarnAboutPairForCurrentProject( sourceCrs, destinationCrs ) )
return;

const QString shortMessage = tr( "Cannot use project transform between %1 and %2" ).arg( sourceCrs.userFriendlyIdentifier( true ),
destinationCrs.userFriendlyIdentifier( true ) );
const QString shortMessage = tr( "Cannot use project transform between %1 and %2" ).arg( sourceCrs.userFriendlyIdentifier( QgsCoordinateReferenceSystem::ShortString ),
destinationCrs.userFriendlyIdentifier( QgsCoordinateReferenceSystem::ShortString ) );

QString gridMessage;
QString downloadMessage;
@@ -1283,22 +1283,25 @@ QString QgsCoordinateReferenceSystem::description() const
}
}

QString QgsCoordinateReferenceSystem::userFriendlyIdentifier( bool shortString ) const
QString QgsCoordinateReferenceSystem::userFriendlyIdentifier( IdentifierType type ) const
{
if ( !authid().isEmpty() )
{
if ( !shortString && !description().isEmpty() )
if ( type != ShortString && !description().isEmpty() )
return QStringLiteral( "%1 - %2" ).arg( authid(), description() );
return authid();
}
else if ( !description().isEmpty() )
return description();
else if ( shortString )
else if ( type == ShortString )
return QObject::tr( "Unknown CRS" );
else if ( !toWkt( WKT2_2018 ).isEmpty() )
return QObject::tr( "Unknown CRS: %1" ).arg( toWkt( WKT2_2018 ).left( 50 ) + QString( QChar( 0x2026 ) ) );
return QObject::tr( "Unknown CRS: %1" ).arg(
type == MediumString ? ( toWkt( WKT2_2018 ).left( 50 ) + QString( QChar( 0x2026 ) ) )
: toWkt( WKT2_2018 ) );
else if ( !toProj().isEmpty() )
return QObject::tr( "Unknown CRS: %1" ).arg( toProj().left( 50 ) + QString( QChar( 0x2026 ) ) );
return QObject::tr( "Unknown CRS: %1" ).arg( type == MediumString ? ( toProj().left( 50 ) + QString( QChar( 0x2026 ) ) )
: toProj() );
else
return QString();
}
@@ -608,6 +608,18 @@ class CORE_EXPORT QgsCoordinateReferenceSystem
*/
QString description() const;

/**
* Type of identifier string to create.
*
* \since QGIS 3.10.3
*/
enum IdentifierType
{
ShortString, //!< A heavily abbreviated string, for use when a compact representation is required
MediumString, //!< A medium-length string, recommended for general purpose use
FullString, //!< Full definition -- possibly a very lengthy string, e.g. with no truncation of custom WKT definitions
};

/**
* Returns a user friendly identifier for the CRS.
*
@@ -618,12 +630,10 @@ class CORE_EXPORT QgsCoordinateReferenceSystem
* In most cases this is the best method to use when showing a friendly identifier for the CRS to a
* user.
*
* If \a shortString is TRUE than an abbreviated identifier will be returned.
*
* \see description()
* \since QGIS 3.10.3
*/
QString userFriendlyIdentifier( bool shortString = false ) const;
QString userFriendlyIdentifier( IdentifierType type = MediumString ) const;

/**
* Returns the projection acronym for the projection used by the CRS.
@@ -4909,7 +4909,7 @@ QString QgsVectorLayer::htmlMetadata() const
myMetadata += QStringLiteral( "<tr><td class=\"highlight\">" ) + tr( "CRS" ) + QStringLiteral( "</td><td>" );
if ( crs().isValid() )
{
myMetadata += crs().userFriendlyIdentifier() + QStringLiteral( " - " );
myMetadata += crs().userFriendlyIdentifier( QgsCoordinateReferenceSystem::FullString ) + QStringLiteral( " - " );
if ( crs().isGeographic() )
myMetadata += tr( "Geographic" );
else
@@ -323,7 +323,7 @@ QString QgsRasterLayer::htmlMetadata() const
myMetadata += QStringLiteral( "<tr><td class=\"highlight\">" ) % tr( "CRS" ) + QStringLiteral( "</td><td>" );
if ( crs().isValid() )
{
myMetadata += crs().userFriendlyIdentifier() % QStringLiteral( " - " );
myMetadata += crs().userFriendlyIdentifier( QgsCoordinateReferenceSystem::FullString ) % QStringLiteral( " - " );
if ( crs().isGeographic() )
myMetadata += tr( "Geographic" );
else
@@ -1553,16 +1553,17 @@ void TestQgsCoordinateReferenceSystem::displayIdentifier()
crs = QgsCoordinateReferenceSystem( QStringLiteral( "EPSG:3111" ) );
QCOMPARE( crs.userFriendlyIdentifier(), QStringLiteral( "EPSG:3111 - GDA94 / Vicgrid" ) );
crs = QgsCoordinateReferenceSystem( QStringLiteral( "EPSG:4326" ) );
QCOMPARE( crs.userFriendlyIdentifier( true ), QStringLiteral( "EPSG:4326" ) );
QCOMPARE( crs.userFriendlyIdentifier( QgsCoordinateReferenceSystem::ShortString ), QStringLiteral( "EPSG:4326" ) );

// non registered custom CRS
crs = QgsCoordinateReferenceSystem::fromProj( QStringLiteral( "+proj=sterea +lat_0=47.9860018439082 +lon_0=19.0491441390302 +k=1 +x_0=500000 +y_0=500000 +ellps=bessel +towgs84=595.75,121.09,515.50,8.2270,-1.5193,5.5971,-2.6729 +units=m +vunits=m +no_defs" ) );
#if PROJ_VERSION_MAJOR>=6
QCOMPARE( crs.userFriendlyIdentifier(), QStringLiteral( "Unknown CRS: BOUNDCRS[SOURCECRS[COMPOUNDCRS[\"unknown\",PROJCRS[\"%1" ).arg( QString( QChar( 0x2026 ) ) ) ); //#spellok
QCOMPARE( crs.userFriendlyIdentifier( QgsCoordinateReferenceSystem::FullString ), QStringLiteral( R"""(Unknown CRS: BOUNDCRS[SOURCECRS[COMPOUNDCRS["unknown",PROJCRS["unknown",BASEGEOGCRS["unknown",DATUM["Unknown based on Bessel 1841 ellipsoid",ELLIPSOID["Bessel 1841",6377397.155,299.1528128,LENGTHUNIT["metre",1,ID["EPSG",9001]]]],PRIMEM["Greenwich",0,ANGLEUNIT["degree",0.0174532925199433],ID["EPSG",8901]]],CONVERSION["unknown",METHOD["Oblique Stereographic",ID["EPSG",9809]],PARAMETER["Latitude of natural origin",47.9860018439082,ANGLEUNIT["degree",0.0174532925199433],ID["EPSG",8801]],PARAMETER["Longitude of natural origin",19.0491441390302,ANGLEUNIT["degree",0.0174532925199433],ID["EPSG",8802]],PARAMETER["Scale factor at natural origin",1,SCALEUNIT["unity",1],ID["EPSG",8805]],PARAMETER["False easting",500000,LENGTHUNIT["metre",1],ID["EPSG",8806]],PARAMETER["False northing",500000,LENGTHUNIT["metre",1],ID["EPSG",8807]]],CS[Cartesian,2],AXIS["(E)",east,ORDER[1],LENGTHUNIT["metre",1,ID["EPSG",9001]]],AXIS["(N)",north,ORDER[2],LENGTHUNIT["metre",1,ID["EPSG",9001]]]],VERTCRS["unknown",VDATUM["unknown"],CS[vertical,1],AXIS["gravity-related height (H)",up,LENGTHUNIT["metre",1,ID["EPSG",9001]]]]]],TARGETCRS[GEOGCRS["WGS 84",DATUM["World Geodetic System 1984",ELLIPSOID["WGS 84",6378137,298.257223563,LENGTHUNIT["metre",1]]],PRIMEM["Greenwich",0,ANGLEUNIT["degree",0.0174532925199433]],CS[ellipsoidal,2],AXIS["latitude",north,ORDER[1],ANGLEUNIT["degree",0.0174532925199433]],AXIS["longitude",east,ORDER[2],ANGLEUNIT["degree",0.0174532925199433]],ID["EPSG",4326]]],ABRIDGEDTRANSFORMATION["Transformation from unknown to WGS84",METHOD["Position Vector transformation (geog2D domain)",ID["EPSG",9606]],PARAMETER["X-axis translation",595.75,ID["EPSG",8605]],PARAMETER["Y-axis translation",121.09,ID["EPSG",8606]],PARAMETER["Z-axis translation",515.5,ID["EPSG",8607]],PARAMETER["X-axis rotation",8.227,ID["EPSG",8608]],PARAMETER["Y-axis rotation",-1.5193,ID["EPSG",8609]],PARAMETER["Z-axis rotation",5.5971,ID["EPSG",8610]],PARAMETER["Scale difference",0.9999973271,ID["EPSG",8611]]]])""" ) );
#else
QCOMPARE( crs.userFriendlyIdentifier(), QStringLiteral( "Unknown CRS: PROJCS[\"unnamed\",GEOGCS[\"Bessel 1841\",DATUM[\"unkno%1" ).arg( QString( QChar( 0x2026 ) ) ) );
#endif
QCOMPARE( crs.userFriendlyIdentifier( true ), QStringLiteral( "Unknown CRS" ) );
QCOMPARE( crs.userFriendlyIdentifier( QgsCoordinateReferenceSystem::ShortString ), QStringLiteral( "Unknown CRS" ) );
crs.saveAsUserCrs( QStringLiteral( "my test" ) );
#if PROJ_VERSION_MAJOR>=6
QCOMPARE( crs.userFriendlyIdentifier(), QStringLiteral( "USER:100011 - my test" ) );

0 comments on commit 19d58bd

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