Skip to content

Commit

Permalink
Use proj6 api for geographicCrsAuthId(), add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Apr 15, 2019
1 parent 3bab21d commit d831f4e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/core/qgscoordinatereferencesystem.cpp
Expand Up @@ -2428,10 +2428,18 @@ QString QgsCoordinateReferenceSystem::geographicCrsAuthId() const
{
return d->mAuthId;
}
#if PROJ_VERSION_MAJOR>=6
else if ( d->mPj )
{
QgsProjUtils::proj_pj_unique_ptr geoCrs( proj_crs_get_geodetic_crs( QgsProjContext::get(), d->mPj.get() ) );
return geoCrs ? QStringLiteral( "%1:%2" ).arg( proj_get_id_auth_name( geoCrs.get(), 0 ), proj_get_id_code( geoCrs.get(), 0 ) ) : QString();
}
#else
else if ( d->mCRS )
{
return OSRGetAuthorityName( d->mCRS, "GEOGCS" ) + QStringLiteral( ":" ) + OSRGetAuthorityCode( d->mCRS, "GEOGCS" );
}
#endif
else
{
return QString();
Expand Down
12 changes: 12 additions & 0 deletions tests/src/core/testqgscoordinatereferencesystem.cpp
Expand Up @@ -84,6 +84,7 @@ class TestQgsCoordinateReferenceSystem: public QObject
void projectWithCustomCrs();
void projectEPSG25833();
void geoCcsDescription();
void geographicCrsAuthId();

private:
void debugPrint( QgsCoordinateReferenceSystem &crs );
Expand Down Expand Up @@ -922,5 +923,16 @@ void TestQgsCoordinateReferenceSystem::geoCcsDescription()
QCOMPARE( crs.authid(), QStringLiteral( "EPSG:4348" ) );
QCOMPARE( crs.description(), QStringLiteral( "GDA94 (geocentric)" ) );
}

void TestQgsCoordinateReferenceSystem::geographicCrsAuthId()
{
QgsCoordinateReferenceSystem crs;
crs.createFromString( QStringLiteral( "EPSG:4326" ) );
QCOMPARE( crs.authid(), QStringLiteral( "EPSG:4326" ) );
QCOMPARE( crs.geographicCrsAuthId(), QStringLiteral( "EPSG:4326" ) );
crs.createFromString( QStringLiteral( "EPSG:3825" ) );
QCOMPARE( crs.authid(), QStringLiteral( "EPSG:3825" ) );
QCOMPARE( crs.geographicCrsAuthId(), QStringLiteral( "EPSG:3824" ) );
}
QGSTEST_MAIN( TestQgsCoordinateReferenceSystem )
#include "testqgscoordinatereferencesystem.moc"

0 comments on commit d831f4e

Please sign in to comment.