QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
qgscoordinatetransform_p.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgscoordinatetransform_p.h
3  --------------------------
4  begin : July 2016
5  copyright : (C) 2016 Nyall Dawson
6  email : nyall dot dawson at gmail dot com
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 #ifndef QGSCOORDINATETRANSFORMPRIVATE_H
18 #define QGSCOORDINATETRANSFORMPRIVATE_H
19 
20 #define SIP_NO_FILE
21 #include "qgsconfig.h"
22 
24 
25 //
26 // W A R N I N G
27 // -------------
28 //
29 // This file is not part of the QGIS API. It exists purely as an
30 // implementation detail. This header file may change from version to
31 // version without notice, or even be removed.
32 //
33 
34 #include <QSharedData>
35 
36 #if PROJ_VERSION_MAJOR<6
37 typedef void *projPJ;
38 #ifndef USE_THREAD_LOCAL
39 #include <QThreadStorage>
40 #endif
41 typedef QPair< projPJ, projPJ > ProjData;
42 #else
43 struct PJconsts;
44 typedef struct PJconsts PJ;
45 typedef PJ *ProjData;
46 #endif
47 
50 
51 #if PROJ_VERSION_MAJOR<6
52 
53 typedef void *projCtx;
54 
60 class QgsProjContextStore
61 {
62  public:
63 
64  QgsProjContextStore();
65  ~QgsProjContextStore();
66 
67  projCtx get() { return context; }
68 
69  private:
70  projCtx context;
71 };
72 
73 #endif
74 
75 class QgsCoordinateTransformPrivate : public QSharedData
76 {
77 
78  public:
79 
80  explicit QgsCoordinateTransformPrivate();
81 
82  QgsCoordinateTransformPrivate( const QgsCoordinateReferenceSystem &source,
83  const QgsCoordinateReferenceSystem &destination,
84  const QgsCoordinateTransformContext &context );
85 
86  QgsCoordinateTransformPrivate( const QgsCoordinateReferenceSystem &source,
87  const QgsCoordinateReferenceSystem &destination,
88  int sourceDatumTransform,
89  int destDatumTransform );
90 
91  QgsCoordinateTransformPrivate( const QgsCoordinateTransformPrivate &other );
92 
93  ~QgsCoordinateTransformPrivate();
94 
95  bool checkValidity();
96 
97  void invalidate();
98 
99  bool initialize();
100 
101  void calculateTransforms( const QgsCoordinateTransformContext &context );
102 
103  ProjData threadLocalProjData();
104 
105 #if PROJ_VERSION_MAJOR>=6
106  int mAvailableOpCount = -1;
107  ProjData threadLocalFallbackProjData();
108 
109  // Only meant to be called by QgsCoordinateTransform::removeFromCacheObjectsBelongingToCurrentThread()
110  bool removeObjectsBelongingToCurrentThread( void *pj_context );
111 #endif
112 
117  bool mIsValid = false;
118 
123  bool mShortCircuit = false;
124 
126  QgsCoordinateReferenceSystem mSourceCRS;
127 
130 
131  Q_DECL_DEPRECATED QString mSourceProjString;
132  Q_DECL_DEPRECATED QString mDestProjString;
133 
134  Q_DECL_DEPRECATED int mSourceDatumTransform = -1;
135  Q_DECL_DEPRECATED int mDestinationDatumTransform = -1;
136  QString mProjCoordinateOperation;
137  bool mShouldReverseCoordinateOperation = false;
138  bool mAllowFallbackTransforms = true;
139 
141  bool mIsReversed = false;
142 
143 #if PROJ_VERSION_MAJOR<6
144 
149 #ifdef USE_THREAD_LOCAL
150  static thread_local QgsProjContextStore mProjContext;
151 #else
152  static QThreadStorage< QgsProjContextStore * > mProjContext;
153 #endif
154 #endif
155 
156 
157  QReadWriteLock mProjLock;
158  QMap < uintptr_t, ProjData > mProjProjections;
159  QMap < uintptr_t, ProjData > mProjFallbackProjections;
160 
168  static void setCustomMissingRequiredGridHandler( const std::function< void( const QgsCoordinateReferenceSystem &sourceCrs,
169  const QgsCoordinateReferenceSystem &destinationCrs,
170  const QgsDatumTransform::GridDetails &grid )> &handler );
171 
183  static void setCustomMissingPreferredGridHandler( const std::function< void( const QgsCoordinateReferenceSystem &sourceCrs,
184  const QgsCoordinateReferenceSystem &destinationCrs,
185  const QgsDatumTransform::TransformDetails &preferredOperation,
186  const QgsDatumTransform::TransformDetails &availableOperation )> &handler );
187 
195  static void setCustomCoordinateOperationCreationErrorHandler( const std::function< void( const QgsCoordinateReferenceSystem &sourceCrs,
196  const QgsCoordinateReferenceSystem &destinationCrs,
197  const QString &error )> &handler );
198 
206  static void setCustomMissingGridUsedByContextHandler( const std::function< void( const QgsCoordinateReferenceSystem &sourceCrs,
207  const QgsCoordinateReferenceSystem &destinationCrs,
208  const QgsDatumTransform::TransformDetails &desiredOperation )> &handler );
209 
210  private:
211 
212 #if PROJ_VERSION_MAJOR<6
213  Q_DECL_DEPRECATED QString stripDatumTransform( const QString &proj4 ) const;
215 
217  Q_DECL_DEPRECATED void addNullGridShifts( QString &srcProjString, QString &destProjString, int sourceDatumTransform, int destinationDatumTransform ) const;
218 #endif
219 
220  void freeProj();
221 
222  static std::function< void( const QgsCoordinateReferenceSystem &sourceCrs,
223  const QgsCoordinateReferenceSystem &destinationCrs,
224  const QgsDatumTransform::GridDetails &grid )> sMissingRequiredGridHandler;
225 
226  static std::function< void( const QgsCoordinateReferenceSystem &sourceCrs,
227  const QgsCoordinateReferenceSystem &destinationCrs,
228  const QgsDatumTransform::TransformDetails &preferredOperation,
229  const QgsDatumTransform::TransformDetails &availableOperation )> sMissingPreferredGridHandler;
230 
231  static std::function< void( const QgsCoordinateReferenceSystem &sourceCrs,
232  const QgsCoordinateReferenceSystem &destinationCrs,
233  const QString &error )> sCoordinateOperationCreationErrorHandler;
234 
235  static std::function< void( const QgsCoordinateReferenceSystem &sourceCrs,
236  const QgsCoordinateReferenceSystem &destinationCrs,
237  const QgsDatumTransform::TransformDetails &desiredOperation )> sMissingGridUsedByContextHandler;
238 
239  QgsCoordinateTransformPrivate &operator= ( const QgsCoordinateTransformPrivate & ) = delete;
240 };
241 
243 
244 #endif // QGSCOORDINATETRANSFORMPRIVATE_H
QgsCoordinateTransformContext
Contains information about the context in which a coordinate transform is executed.
Definition: qgscoordinatetransformcontext.h:58
qgscoordinatetransformcontext.h
QgsDatumTransform::GridDetails
Contains information about a projection transformation grid file.
Definition: qgsdatumtransform.h:134
QgsDatumTransform::TransformDetails
Contains information about a coordinate transformation operation.
Definition: qgsdatumtransform.h:182
QgsCoordinateReferenceSystem
This class represents a coordinate reference system (CRS).
Definition: qgscoordinatereferencesystem.h:206
qgscoordinatereferencesystem.h