Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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 20, 2019
1 parent 4edab2b commit 7136406
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/core/qgsproject.cpp
Expand Up @@ -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 );
}
Expand Down

0 comments on commit 7136406

Please sign in to comment.