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.
  • Loading branch information
nyalldawson committed Dec 17, 2019
1 parent 4edab2b commit 71364060479c2eb4ecc16ad7bdd3e0598ff58b7e
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 7136406

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