Skip to content

Commit f124b5d

Browse files
committedJul 26, 2016
Clean up handling of inverted axis for CRS, fix detachment issue
(cherry-picked from 6dac8e1)
1 parent 9b7c880 commit f124b5d

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed
 

‎src/core/qgscoordinatereferencesystem.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -238,9 +238,12 @@ bool QgsCoordinateReferenceSystem::createFromOgcWmsCrs( const QString& theCrs )
238238
if ( wmsCrs.compare( "CRS:84", Qt::CaseInsensitive ) == 0 ||
239239
wmsCrs.compare( "OGC:CRS84", Qt::CaseInsensitive ) == 0 )
240240
{
241-
d.detach();
242241
createFromOgcWmsCrs( "EPSG:4326" );
243-
d->mAxisInverted = 0;
242+
243+
d.detach();
244+
d->mAxisInverted = false;
245+
d->mAxisInvertedDirty = false;
246+
244247
return d->mIsValid;
245248
}
246249

@@ -337,7 +340,7 @@ bool QgsCoordinateReferenceSystem::loadFromDb( const QString& db, const QString&
337340
d->mSRID = QString::fromUtf8( reinterpret_cast< const char * >( sqlite3_column_text( myPreparedStatement, 5 ) ) ).toLong() ;
338341
d->mAuthId = QString::fromUtf8( reinterpret_cast< const char * >( sqlite3_column_text( myPreparedStatement, 6 ) ) );
339342
d->mIsGeographic = QString::fromUtf8( reinterpret_cast< const char * >( sqlite3_column_text( myPreparedStatement, 7 ) ) ).toInt() != 0;
340-
d->mAxisInverted = -1;
343+
d->mAxisInvertedDirty = true;
341344

342345
if ( d->mSrsId >= USER_CRS_START_ID && d->mAuthId.isEmpty() )
343346
{
@@ -367,7 +370,7 @@ bool QgsCoordinateReferenceSystem::loadFromDb( const QString& db, const QString&
367370

368371
bool QgsCoordinateReferenceSystem::axisInverted() const
369372
{
370-
if ( d->mAxisInverted == -1 )
373+
if ( d->mAxisInvertedDirty )
371374
{
372375
OGRAxisOrientation orientation;
373376
OSRGetAxis( d->mCRS, OSRIsGeographic( d->mCRS ) ? "GEOGCS" : "PROJCS", 0, &orientation );
@@ -386,9 +389,10 @@ bool QgsCoordinateReferenceSystem::axisInverted() const
386389
}
387390

388391
d->mAxisInverted = orientation == OAO_North;
392+
d->mAxisInvertedDirty = false;
389393
}
390394

391-
return d->mAxisInverted != 0;
395+
return d->mAxisInverted;
392396
}
393397

394398
bool QgsCoordinateReferenceSystem::createFromWkt( const QString &theWkt )

‎src/core/qgscoordinatereferencesystem_p.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ class QgsCoordinateReferenceSystemPrivate : public QSharedData
4949
, mSRID( 0 )
5050
, mIsValid( 0 )
5151
, mCRS( OSRNewSpatialReference( nullptr ) )
52+
, mAxisInvertedDirty( false )
5253
, mAxisInverted( false )
5354
{
5455
}
@@ -68,6 +69,7 @@ class QgsCoordinateReferenceSystemPrivate : public QSharedData
6869
, mValidationHint( other.mValidationHint )
6970
, mWkt( other.mWkt )
7071
, mProj4( other.mProj4 )
72+
, mAxisInvertedDirty( other.mAxisInvertedDirty )
7173
, mAxisInverted( other.mAxisInverted )
7274
{
7375
if ( mIsValid )
@@ -114,8 +116,11 @@ class QgsCoordinateReferenceSystemPrivate : public QSharedData
114116
mutable QString mWkt;
115117
mutable QString mProj4;
116118

119+
//! True if presence of an inverted axis needs to be recaculated
120+
mutable bool mAxisInvertedDirty;
121+
117122
//! Whether this is a coordinate system has inverted axis
118-
mutable int mAxisInverted;
123+
mutable bool mAxisInverted;
119124

120125
};
121126

0 commit comments

Comments
 (0)
Please sign in to comment.