18 #ifndef QGSCOORDINATEREFERENCESYSTEM_PRIVATE_H
19 #define QGSCOORDINATEREFERENCESYSTEM_PRIVATE_H
34 #if PROJ_VERSION_MAJOR>=6
39 #include <ogr_srs_api.h>
48 class QgsCoordinateReferenceSystemPrivate :
public QSharedData
52 explicit QgsCoordinateReferenceSystemPrivate()
53 #if PROJ_VERSION_MAJOR<6
54 : mCRS( OSRNewSpatialReference(
nullptr ) )
59 QgsCoordinateReferenceSystemPrivate(
const QgsCoordinateReferenceSystemPrivate &other )
60 : QSharedData( other )
61 , mSrsId( other.mSrsId )
62 , mDescription( other.mDescription )
63 , mProjectionAcronym( other.mProjectionAcronym )
64 , mEllipsoidAcronym( other.mEllipsoidAcronym )
65 , mIsGeographic( other.mIsGeographic )
66 , mMapUnits( other.mMapUnits )
67 , mSRID( other.mSRID )
68 , mAuthId( other.mAuthId )
69 , mIsValid( other.mIsValid )
70 #if PROJ_VERSION_MAJOR >= 6
75 , mProj4( other.mProj4 )
76 , mWktPreferred( other.mWktPreferred )
77 , mAxisInvertedDirty( other.mAxisInvertedDirty )
78 , mAxisInverted( other.mAxisInverted )
79 #if PROJ_VERSION_MAJOR >= 6
83 #if PROJ_VERSION_MAJOR<6
86 mCRS = OSRClone( other.mCRS );
90 mCRS = OSRNewSpatialReference(
nullptr );
95 ~QgsCoordinateReferenceSystemPrivate()
97 #if PROJ_VERSION_MAJOR>=6
101 OSRDestroySpatialReference( mCRS );
109 QString mDescription;
112 QString mProjectionAcronym;
115 QString mEllipsoidAcronym;
118 bool mIsGeographic =
false;
130 bool mIsValid =
false;
132 #if PROJ_VERSION_MAJOR>=6
138 QgsProjUtils::proj_pj_unique_ptr mPj;
141 void cleanPjObjects()
149 PJ_CONTEXT *tmpContext = proj_context_create();
150 for (
auto it = mProjObjects.begin(); it != mProjObjects.end(); ++it )
152 proj_assign_context( it.value(), tmpContext );
153 proj_destroy( it.value() );
155 mProjObjects.clear();
158 proj_assign_context( mPj.get(), tmpContext );
161 proj_context_destroy( tmpContext );
166 void setPj( QgsProjUtils::proj_pj_unique_ptr obj )
171 mPj = std::move( obj );
178 return static_cast< bool >( mPj );
185 mutable QString mProj4;
187 mutable QString mWktPreferred;
190 mutable bool mAxisInvertedDirty =
false;
193 mutable bool mAxisInverted =
false;
195 #if PROJ_VERSION_MAJOR>=6
197 mutable QReadWriteLock mProjLock{};
198 mutable QMap < PJ_CONTEXT *, PJ * > mProjObjects{};
202 PJ *threadLocalProjObject()
const
209 QMap < PJ_CONTEXT *, PJ * >::const_iterator it = mProjObjects.constFind( context );
211 if ( it != mProjObjects.constEnd() )
219 PJ *res = proj_clone( context, mPj.get() );
220 mProjObjects.insert( context, res );
225 bool removeObjectsBelongingToCurrentThread(
PJ_CONTEXT *pj_context )
229 QMap < PJ_CONTEXT *, PJ * >::iterator it = mProjObjects.find( pj_context );
230 if ( it != mProjObjects.end() )
232 proj_destroy( it.value() );
233 mProjObjects.erase( it );
236 if ( mPjParentContext == pj_context )
239 mPjParentContext =
nullptr;
242 return mProjObjects.isEmpty();
247 QgsCoordinateReferenceSystemPrivate &operator= (
const QgsCoordinateReferenceSystemPrivate & ) =
delete;
253 #endif //QGSCOORDINATEREFERENCESYSTEM_PRIVATE_H