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
73 , mProj4( other.mProj4 )
74 , mAxisInvertedDirty( other.mAxisInvertedDirty )
75 , mAxisInverted( other.mAxisInverted )
77 #if PROJ_VERSION_MAJOR<6 80 mCRS = OSRClone( other.mCRS );
84 mCRS = OSRNewSpatialReference(
nullptr );
89 ~QgsCoordinateReferenceSystemPrivate()
91 #if PROJ_VERSION_MAJOR>=6 95 OSRDestroySpatialReference( mCRS );
103 QString mDescription;
106 QString mProjectionAcronym;
109 QString mEllipsoidAcronym;
112 bool mIsGeographic =
false;
124 bool mIsValid =
false;
126 #if PROJ_VERSION_MAJOR>=6 132 QgsProjUtils::proj_pj_unique_ptr mPj;
135 void cleanPjObjects()
143 PJ_CONTEXT *tmpContext = proj_context_create();
144 for (
auto it = mProjObjects.begin(); it != mProjObjects.end(); ++it )
146 proj_assign_context( it.value(), tmpContext );
147 proj_destroy( it.value() );
149 mProjObjects.clear();
152 proj_assign_context( mPj.get(), tmpContext );
155 proj_context_destroy( tmpContext );
160 void setPj( QgsProjUtils::proj_pj_unique_ptr obj )
165 mPj = std::move( obj );
172 return static_cast< bool >( mPj );
179 mutable QString mProj4;
182 mutable bool mAxisInvertedDirty =
false;
185 mutable bool mAxisInverted =
false;
187 #if PROJ_VERSION_MAJOR>=6 189 mutable QReadWriteLock mProjLock;
190 mutable QMap < PJ_CONTEXT *, PJ * > mProjObjects;
194 PJ *threadLocalProjObject()
const 201 QMap < PJ_CONTEXT *, PJ * >::const_iterator it = mProjObjects.constFind( context );
203 if ( it != mProjObjects.constEnd() )
211 PJ *res = proj_clone( context, mPj.get() );
212 mProjObjects.insert( context, res );
217 bool removeObjectsBelongingToCurrentThread(
PJ_CONTEXT *pj_context )
221 QMap < PJ_CONTEXT *, PJ * >::iterator it = mProjObjects.find( pj_context );
222 if ( it != mProjObjects.end() )
224 proj_destroy( it.value() );
225 mProjObjects.erase( it );
228 if ( mPjParentContext == pj_context )
231 mPjParentContext =
nullptr;
234 return mProjObjects.isEmpty();
243 #endif //QGSCOORDINATEREFERENCESYSTEM_PRIVATE_H
The QgsReadWriteLocker class is a convenience class that simplifies locking and unlocking QReadWriteL...
DistanceUnit
Units of distance.
static PJ_CONTEXT * get()
Returns a thread local instance of a proj context, safe for use in the current thread.
void * OGRSpatialReferenceH