Skip to content
Permalink
Browse files

Fix projection mismatch when reading very old projects on proj 6 builds

We should always prioritise an exact auth:id means of constructing
CRSes whenever it's available, instead of just starting with a proj string.

(cherry picked from commit 7136406)
  • Loading branch information
nyalldawson committed Dec 17, 2019
1 parent 61e1923 commit ce6b928a2290bc2191b17e6fccf6dc9866e3cba4
Showing with 8 additions and 2 deletions.
  1. +8 −2 src/core/qgsproject.cpp
@@ -1274,15 +1274,21 @@ bool QgsProject::readProjectFile( const QString &filename, QgsProject::ReadFlags
{
QString projCrsString = readEntry( QStringLiteral( "SpatialRefSys" ), QStringLiteral( "/ProjectCRSProj4String" ) );
long currentCRS = readNumEntry( QStringLiteral( "SpatialRefSys" ), QStringLiteral( "/ProjectCRSID" ), -1 );
const QString authid = readEntry( QStringLiteral( "SpatialRefSys" ), QStringLiteral( "/ProjectCrs" ) );

// authid should be prioritised over all
bool isUserAuthId = authid.startsWith( QLatin1String( "USER:" ), Qt::CaseInsensitive );
if ( !authid.isEmpty() && !isUserAuthId )
projectCrs = QgsCoordinateReferenceSystem( authid );

// try the CRS
if ( currentCRS >= 0 )
if ( !projectCrs.isValid() && currentCRS >= 0 )
{
projectCrs = QgsCoordinateReferenceSystem::fromSrsId( currentCRS );
}

// if that didn't produce a match, try the proj.4 string
if ( !projCrsString.isEmpty() && ( !projectCrs.isValid() || projectCrs.toProj() != projCrsString ) )
if ( !projCrsString.isEmpty() && ( authid.isEmpty() || isUserAuthId ) && ( !projectCrs.isValid() || projectCrs.toProj() != projCrsString ) )
{
projectCrs = QgsCoordinateReferenceSystem::fromProj( projCrsString );
}

0 comments on commit ce6b928

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