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
99 if ( !mProjObjects.empty() || mPj )
105 OSRDestroySpatialReference( mCRS );
113 QString mDescription;
116 QString mProjectionAcronym;
119 QString mEllipsoidAcronym;
122 bool mIsGeographic =
false;
134 bool mIsValid =
false;
136 #if PROJ_VERSION_MAJOR>=6
142 QgsProjUtils::proj_pj_unique_ptr mPj;
145 void cleanPjObjects()
153 PJ_CONTEXT *tmpContext = proj_context_create();
154 for (
auto it = mProjObjects.begin(); it != mProjObjects.end(); ++it )
156 proj_assign_context( it.value(), tmpContext );
157 proj_destroy( it.value() );
159 mProjObjects.clear();
162 proj_assign_context( mPj.get(), tmpContext );
165 proj_context_destroy( tmpContext );
170 void setPj( QgsProjUtils::proj_pj_unique_ptr obj )
175 mPj = std::move( obj );
182 return static_cast< bool >( mPj );
189 mutable QString mProj4;
191 mutable QString mWktPreferred;
194 mutable bool mAxisInvertedDirty =
false;
197 mutable bool mAxisInverted =
false;
199 #if PROJ_VERSION_MAJOR>=6
201 mutable QReadWriteLock mProjLock{};
202 mutable QMap < PJ_CONTEXT *, PJ * > mProjObjects{};
206 PJ *threadLocalProjObject()
const
213 QMap < PJ_CONTEXT *, PJ * >::const_iterator it = mProjObjects.constFind( context );
215 if ( it != mProjObjects.constEnd() )
223 PJ *res = proj_clone( context, mPj.get() );
224 mProjObjects.insert( context, res );
229 bool removeObjectsBelongingToCurrentThread(
PJ_CONTEXT *pj_context )
233 QMap < PJ_CONTEXT *, PJ * >::iterator it = mProjObjects.find( pj_context );
234 if ( it != mProjObjects.end() )
236 proj_destroy( it.value() );
237 mProjObjects.erase( it );
240 if ( mPjParentContext == pj_context )
243 mPjParentContext =
nullptr;
246 return mProjObjects.isEmpty();
251 QgsCoordinateReferenceSystemPrivate &operator= (
const QgsCoordinateReferenceSystemPrivate & ) =
delete;
static PJ_CONTEXT * get()
Returns a thread local instance of a proj context, safe for use in the current thread.
The QgsReadWriteLocker class is a convenience class that simplifies locking and unlocking QReadWriteL...
DistanceUnit
Units of distance.
@ DistanceUnknownUnit
Unknown distance unit.
void * OGRSpatialReferenceH