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 , mIsGeographicCrossingAntimeridian( other.mIsGeographicCrossingAntimeridian )
52 , mMapUnits( other.mMapUnits )
53 , mSRID( other.mSRID )
54 , mAuthId( other.mAuthId )
55 , mIsValid( other.mIsValid )
56 , mCoordinateEpoch( other.mCoordinateEpoch )
57 , mTopocentricBaseCrs( other.mTopocentricBaseCrs ? std::make_unique<QgsCoordinateReferenceSystem>( *other.mTopocentricBaseCrs ) : nullptr )
59 , mPjParentContext( nullptr )
60 , mProj4( other.mProj4 )
61 , mWktPreferred( other.mWktPreferred )
62 , mAxisInvertedDirty( other.mAxisInvertedDirty )
63 , mAxisInverted( other.mAxisInverted )
68 ~QgsCoordinateReferenceSystemPrivate()
71 if ( !mProjObjects.empty() || mPj )
85 QString mProjectionAcronym;
88 QString mEllipsoidAcronym;
90 PJ_TYPE mProjType = PJ_TYPE::PJ_TYPE_UNKNOWN;
93 bool mIsGeographic =
false;
96 bool mIsGeographicCrossingAntimeridian =
false;
108 bool mIsValid =
false;
111 double mCoordinateEpoch = std::numeric_limits< double >::quiet_NaN();
114 std::unique_ptr<QgsCoordinateReferenceSystem> mTopocentricBaseCrs;
123 void cleanPjObjects()
130 PJ_CONTEXT *tmpContext = proj_context_create();
131 for (
auto it = mProjObjects.begin(); it != mProjObjects.end(); ++it )
133 proj_assign_context( it.value(), tmpContext );
134 proj_destroy( it.value() );
136 mProjObjects.clear();
139 proj_assign_context( mPj.get(), tmpContext );
142 proj_context_destroy( tmpContext );
151 mPj = std::move( obj );
156 mProjType = proj_get_type( mPj.get() );
160 mProjType = PJ_TYPE_UNKNOWN;
167 return static_cast< bool >( mPj );
170 mutable QString mProj4;
172 mutable QString mWktPreferred;
175 mutable bool mAxisInvertedDirty =
false;
178 mutable bool mAxisInverted =
false;
181 mutable QReadWriteLock mProjLock {};
182 mutable QMap< PJ_CONTEXT *, PJ * > mProjObjects {};
185 PJ *threadLocalProjObject()
const
192 const QMap< PJ_CONTEXT *, PJ * >::const_iterator it = mProjObjects.constFind( context );
194 if ( it != mProjObjects.constEnd() )
202 PJ *res = proj_clone( context, mPj.get() );
203 mProjObjects.insert( context, res );
208 bool removeObjectsBelongingToCurrentThread(
PJ_CONTEXT *pj_context )
212 const QMap< PJ_CONTEXT *, PJ * >::iterator it = mProjObjects.find( pj_context );
213 if ( it != mProjObjects.end() )
215 proj_destroy( it.value() );
216 mProjObjects.erase( it );
219 if ( mPjParentContext == pj_context )
222 mPjParentContext =
nullptr;
225 return mProjObjects.isEmpty();
229 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.