18#ifndef QGSCOORDINATEREFERENCESYSTEM_PRIVATE_H
19#define QGSCOORDINATEREFERENCESYSTEM_PRIVATE_H
38class QgsCoordinateReferenceSystemPrivate :
public QSharedData
41 explicit QgsCoordinateReferenceSystemPrivate() {}
43 QgsCoordinateReferenceSystemPrivate(
const QgsCoordinateReferenceSystemPrivate &other )
44 : QSharedData( other )
45 , mSrsId( other.mSrsId )
46 , mDescription( other.mDescription )
47 , mProjectionAcronym( other.mProjectionAcronym )
48 , mEllipsoidAcronym( other.mEllipsoidAcronym )
49 , mProjType( other.mProjType )
50 , mIsGeographic( other.mIsGeographic )
51 , mMapUnits( other.mMapUnits )
52 , mSRID( other.mSRID )
53 , mAuthId( other.mAuthId )
54 , mIsValid( other.mIsValid )
55 , mCoordinateEpoch( other.mCoordinateEpoch )
56 , mTopocentricBaseCrs( other.mTopocentricBaseCrs ? std::make_unique<QgsCoordinateReferenceSystem>( *other.mTopocentricBaseCrs ) : nullptr )
58 , mPjParentContext( nullptr )
59 , mProj4( other.mProj4 )
60 , mWktPreferred( other.mWktPreferred )
61 , mAxisInvertedDirty( other.mAxisInvertedDirty )
62 , mAxisInverted( other.mAxisInverted )
67 ~QgsCoordinateReferenceSystemPrivate()
70 if ( !mProjObjects.empty() || mPj )
84 QString mProjectionAcronym;
87 QString mEllipsoidAcronym;
89 PJ_TYPE mProjType = PJ_TYPE::PJ_TYPE_UNKNOWN;
92 bool mIsGeographic =
false;
104 bool mIsValid =
false;
107 double mCoordinateEpoch = std::numeric_limits< double >::quiet_NaN();
110 std::unique_ptr<QgsCoordinateReferenceSystem> mTopocentricBaseCrs;
119 void cleanPjObjects()
126 PJ_CONTEXT *tmpContext = proj_context_create();
127 for (
auto it = mProjObjects.begin(); it != mProjObjects.end(); ++it )
129 proj_assign_context( it.value(), tmpContext );
130 proj_destroy( it.value() );
132 mProjObjects.clear();
135 proj_assign_context( mPj.get(), tmpContext );
138 proj_context_destroy( tmpContext );
147 mPj = std::move( obj );
152 mProjType = proj_get_type( mPj.get() );
156 mProjType = PJ_TYPE_UNKNOWN;
163 return static_cast< bool >( mPj );
166 mutable QString mProj4;
168 mutable QString mWktPreferred;
171 mutable bool mAxisInvertedDirty =
false;
174 mutable bool mAxisInverted =
false;
177 mutable QReadWriteLock mProjLock {};
178 mutable QMap< PJ_CONTEXT *, PJ * > mProjObjects {};
181 PJ *threadLocalProjObject()
const
188 const QMap< PJ_CONTEXT *, PJ * >::const_iterator it = mProjObjects.constFind( context );
190 if ( it != mProjObjects.constEnd() )
198 PJ *res = proj_clone( context, mPj.get() );
199 mProjObjects.insert( context, res );
204 bool removeObjectsBelongingToCurrentThread(
PJ_CONTEXT *pj_context )
208 const QMap< PJ_CONTEXT *, PJ * >::iterator it = mProjObjects.find( pj_context );
209 if ( it != mProjObjects.end() )
211 proj_destroy( it.value() );
212 mProjObjects.erase( it );
215 if ( mPjParentContext == pj_context )
218 mPjParentContext =
nullptr;
221 return mProjObjects.isEmpty();
225 QgsCoordinateReferenceSystemPrivate &operator=(
const QgsCoordinateReferenceSystemPrivate & ) =
delete;
DistanceUnit
Units of distance.
@ Unknown
Unknown distance unit.
static PJ_CONTEXT * get()
Returns a thread local instance of a proj context, safe for use in the current thread.
std::unique_ptr< PJ, ProjPJDeleter > proj_pj_unique_ptr
Scoped Proj PJ object.