Skip to content

Commit

Permalink
Clean up handling of inverted axis for CRS, fix detachment issue
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jul 25, 2016
1 parent bb36c60 commit 6dac8e1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
13 changes: 8 additions & 5 deletions src/core/qgscoordinatereferencesystem.cpp
Expand Up @@ -317,9 +317,11 @@ bool QgsCoordinateReferenceSystem::createFromOgcWmsCrs( const QString& theCrs )
if ( wmsCrs.compare( "CRS:84", Qt::CaseInsensitive ) == 0 ||
wmsCrs.compare( "OGC:CRS84", Qt::CaseInsensitive ) == 0 )
{
d.detach();
createFromOgcWmsCrs( "EPSG:4326" );
d->mAxisInverted = 0;

d.detach();
d->mAxisInverted = false;
d->mAxisInvertedDirty = false;

mOgcLock.lockForWrite();
mOgcCache.insert( theCrs, *this );
Expand Down Expand Up @@ -458,7 +460,7 @@ bool QgsCoordinateReferenceSystem::loadFromDb( const QString& db, const QString&
d->mSRID = QString::fromUtf8( reinterpret_cast< const char * >( sqlite3_column_text( myPreparedStatement, 5 ) ) ).toLong() ;
d->mAuthId = QString::fromUtf8( reinterpret_cast< const char * >( sqlite3_column_text( myPreparedStatement, 6 ) ) );
d->mIsGeographic = QString::fromUtf8( reinterpret_cast< const char * >( sqlite3_column_text( myPreparedStatement, 7 ) ) ).toInt() != 0;
d->mAxisInverted = -1;
d->mAxisInvertedDirty = true;

if ( d->mSrsId >= USER_CRS_START_ID && d->mAuthId.isEmpty() )
{
Expand Down Expand Up @@ -488,7 +490,7 @@ bool QgsCoordinateReferenceSystem::loadFromDb( const QString& db, const QString&

bool QgsCoordinateReferenceSystem::hasAxisInverted() const
{
if ( d->mAxisInverted == -1 )
if ( d->mAxisInvertedDirty )
{
OGRAxisOrientation orientation;
OSRGetAxis( d->mCRS, OSRIsGeographic( d->mCRS ) ? "GEOGCS" : "PROJCS", 0, &orientation );
Expand All @@ -507,9 +509,10 @@ bool QgsCoordinateReferenceSystem::hasAxisInverted() const
}

d->mAxisInverted = orientation == OAO_North;
d->mAxisInvertedDirty = false;
}

return d->mAxisInverted != 0;
return d->mAxisInverted;
}

bool QgsCoordinateReferenceSystem::createFromWkt( const QString &theWkt )
Expand Down
7 changes: 6 additions & 1 deletion src/core/qgscoordinatereferencesystem_p.h
Expand Up @@ -49,6 +49,7 @@ class QgsCoordinateReferenceSystemPrivate : public QSharedData
, mSRID( 0 )
, mIsValid( 0 )
, mCRS( OSRNewSpatialReference( nullptr ) )
, mAxisInvertedDirty( false )
, mAxisInverted( false )
{
}
Expand All @@ -68,6 +69,7 @@ class QgsCoordinateReferenceSystemPrivate : public QSharedData
, mValidationHint( other.mValidationHint )
, mWkt( other.mWkt )
, mProj4( other.mProj4 )
, mAxisInvertedDirty( other.mAxisInvertedDirty )
, mAxisInverted( other.mAxisInverted )
{
if ( mIsValid )
Expand Down Expand Up @@ -114,8 +116,11 @@ class QgsCoordinateReferenceSystemPrivate : public QSharedData
mutable QString mWkt;
mutable QString mProj4;

//! True if presence of an inverted axis needs to be recaculated
mutable bool mAxisInvertedDirty;

//! Whether this is a coordinate system has inverted axis
mutable int mAxisInverted;
mutable bool mAxisInverted;

};

Expand Down

0 comments on commit 6dac8e1

Please sign in to comment.