Skip to content

Commit

Permalink
Show authority:code identifiers on transform selection dialog
Browse files Browse the repository at this point in the history
Many scopes/remark cross reference these, so by showing them in the
table of available operations we give users more clues how to pick
the correct one.

(cherry picked from commit dd9dfb0)
  • Loading branch information
nyalldawson committed Jul 9, 2019
1 parent a01266b commit 8d9a367
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 2 deletions.
8 changes: 8 additions & 0 deletions python/core/auto_generated/qgsdatumtransform.sip.in
Expand Up @@ -89,6 +89,10 @@ and ``destinationTransformId`` transforms.
QString remarks;

QString areaOfUse;

QString authority;

QString code;
};

struct TransformDetails
Expand All @@ -97,6 +101,10 @@ and ``destinationTransformId`` transforms.
QString name;
double accuracy;

QString authority;

QString code;

QString scope;

QString remarks;
Expand Down
5 changes: 5 additions & 0 deletions src/core/qgsdatumtransform.cpp
Expand Up @@ -323,6 +323,9 @@ QgsDatumTransform::TransformDetails QgsDatumTransform::transformDetailsFromPj( P
details.accuracy = proj_coordoperation_get_accuracy( pjContext, op );
details.isAvailable = proj_coordoperation_is_instantiable( pjContext, op );

details.authority = QString( proj_get_id_auth_name( op, 0 ) );
details.code = QString( proj_get_id_code( op, 0 ) );

const char *areaOfUseName = nullptr;
if ( proj_get_area_of_use( pjContext, op, nullptr, nullptr, nullptr, nullptr, &areaOfUseName ) )
{
Expand Down Expand Up @@ -365,6 +368,8 @@ QgsDatumTransform::TransformDetails QgsDatumTransform::transformDetailsFromPj( P
SingleOperationDetails singleOpDetails;
singleOpDetails.remarks = QString( proj_get_remarks( step.get() ) );
singleOpDetails.scope = QString( proj_get_scope( step.get() ) );
singleOpDetails.authority = QString( proj_get_id_auth_name( step.get(), 0 ) );
singleOpDetails.code = QString( proj_get_id_code( step.get(), 0 ) );

const char *areaOfUseName = nullptr;
if ( proj_get_area_of_use( pjContext, step.get(), nullptr, nullptr, nullptr, nullptr, &areaOfUseName ) )
Expand Down
22 changes: 22 additions & 0 deletions src/core/qgsdatumtransform.h
Expand Up @@ -163,6 +163,12 @@ class CORE_EXPORT QgsDatumTransform

//! Area of use, from EPSG registry database
QString areaOfUse;

//! Authority name, e.g. EPSG.
QString authority;

//! Authority code, e.g. "8447" (for EPSG:8447).
QString code;
};

/**
Expand All @@ -180,6 +186,22 @@ class CORE_EXPORT QgsDatumTransform
//! Transformation accuracy (in meters)
double accuracy = 0;

/**
* Authority name, e.g. EPSG.
*
* This is only available for single step coordinate operations. For multi-step operations, check
* \a operationDetails instead.
*/
QString authority;

/**
* Identification code, e.g. "8447" (For EPSG:8447).
*
* This is only available for single step coordinate operations. For multi-step operations, check
* \a operationDetails instead.
*/
QString code;

/**
* Scope of operation, from EPSG registry database.
*
Expand Down
20 changes: 18 additions & 2 deletions src/gui/qgsdatumtransformdialog.cpp
Expand Up @@ -172,7 +172,10 @@ void QgsDatumTransformDialog::load( QPair<int, int> selectedDatumTransforms, con
item->setData( AvailableRole, transform.isAvailable );
item->setFlags( item->flags() & ~Qt::ItemIsEditable );

item->setText( transform.name );
QString name = transform.name;
if ( !transform.authority.isEmpty() && !transform.code.isEmpty() )
name += QStringLiteral( " — %1:%2" ).arg( transform.authority, transform.code );
item->setText( name );

if ( row == 0 ) // highlight first (preferred) operation
{
Expand Down Expand Up @@ -231,6 +234,7 @@ void QgsDatumTransformDialog::load( QPair<int, int> selectedDatumTransforms, con
}

QStringList areasOfUse;
QStringList authorityCodes;

#if PROJ_VERSION_MAJOR > 6 or PROJ_VERSION_MINOR >= 2
QStringList opText;
Expand All @@ -252,6 +256,12 @@ void QgsDatumTransformDialog::load( QPair<int, int> selectedDatumTransforms, con
if ( !areasOfUse.contains( singleOpDetails.areaOfUse ) )
areasOfUse << singleOpDetails.areaOfUse;
}
if ( !singleOpDetails.authority.isEmpty() && !singleOpDetails.code.isEmpty() )
{
const QString identifier = QStringLiteral( "%1:%2" ).arg( singleOpDetails.authority, singleOpDetails.code );
if ( !authorityCodes.contains( identifier ) )
authorityCodes << identifier;
}

if ( !text.isEmpty() )
{
Expand Down Expand Up @@ -285,6 +295,10 @@ void QgsDatumTransformDialog::load( QPair<int, int> selectedDatumTransforms, con
if ( !transform.areaOfUse.isEmpty() && !areasOfUse.contains( transform.areaOfUse ) )
areasOfUse << transform.areaOfUse;

const QString id = QStringLiteral( "%1:%2" ).arg( transform.authority, transform.code );
if ( !transform.authority.isEmpty() && !transform.code.isEmpty() && !authorityCodes.contains( id ) )
authorityCodes << id;

#if PROJ_VERSION_MAJOR > 6 or PROJ_VERSION_MINOR >= 2
const QColor disabled = palette().color( QPalette::Disabled, QPalette::Text );
const QColor active = palette().color( QPalette::Active, QPalette::Text );
Expand All @@ -295,11 +309,13 @@ void QgsDatumTransformDialog::load( QPair<int, int> selectedDatumTransforms, con
const QString toolTipString = QStringLiteral( "<b>%1</b>" ).arg( transform.name )
+ ( !opText.empty() ? ( opText.count() == 1 ? QStringLiteral( "<p>%1</p>" ).arg( opText.at( 0 ) ) : QStringLiteral( "<ul>%1</ul>" ).arg( opText.join( QString() ) ) ) : QString() )
+ ( !areasOfUse.empty() ? QStringLiteral( "<p><b>%1</b>: %2</p>" ).arg( tr( "Area of use" ), areasOfUse.join( QStringLiteral( ", " ) ) ) : QString() )
+ ( !authorityCodes.empty() ? QStringLiteral( "<p><b>%1</b>: %2</p>" ).arg( tr( "Identifiers" ), authorityCodes.join( QStringLiteral( ", " ) ) ) : QString() )
+ ( !missingMessage.isEmpty() ? QStringLiteral( "<p><b style=\"color: red\">%1</b></p>" ).arg( missingMessage ) : QString() )
+ QStringLiteral( "<p><code style=\"color: %1\">%2</code></p>" ).arg( codeColor.name(), transform.proj );
#else
const QString toolTipString = QStringLiteral( "<b>%1</b>%2%3<p><code>%4</code></p>" ).arg( transform.name,
const QString toolTipString = QStringLiteral( "<b>%1</b>%2%3%4<p><code>%5</code></p>" ).arg( transform.name,
( !transform.areaOfUse.isEmpty() ? QStringLiteral( "<p><b>%1</b>: %2</p>" ).arg( tr( "Area of use" ), transform.areaOfUse ) : QString() ),
( !id.isEmpty() ? QStringLiteral( "<p><b>%1</b>: %2</p>" ).arg( tr( "Identifier" ), id ) : QString() ),
( !missingMessage.isEmpty() ? QStringLiteral( "<p><b style=\"color: red\">%1</b></p>" ).arg( missingMessage ) : QString() ),
transform.proj );
#endif
Expand Down

0 comments on commit 8d9a367

Please sign in to comment.