QGIS API Documentation  3.10.0-A Coruña (6c816b4204)
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  // Only meant to be called by QgsCoordinateTransform::removeFromCacheObjectsBelongingToCurrentThread()
107  bool removeObjectsBelongingToCurrentThread( void *pj_context );
108 #endif
109 
114  bool mIsValid = false;
115 
120  bool mShortCircuit = false;
121 
123  QgsCoordinateReferenceSystem mSourceCRS;
124 
127 
128  Q_DECL_DEPRECATED QString mSourceProjString;
129  Q_DECL_DEPRECATED QString mDestProjString;
130 
131  Q_DECL_DEPRECATED int mSourceDatumTransform = -1;
132  Q_DECL_DEPRECATED int mDestinationDatumTransform = -1;
133  QString mProjCoordinateOperation;
134 
135 #if PROJ_VERSION_MAJOR<6
136 
141 #ifdef USE_THREAD_LOCAL
142  static thread_local QgsProjContextStore mProjContext;
143 #else
144  static QThreadStorage< QgsProjContextStore * > mProjContext;
145 #endif
146 #endif
147 
148 
149  QReadWriteLock mProjLock;
150  QMap < uintptr_t, ProjData > mProjProjections;
151 
159  static void setCustomMissingRequiredGridHandler( const std::function< void( const QgsCoordinateReferenceSystem &sourceCrs,
160  const QgsCoordinateReferenceSystem &destinationCrs,
161  const QgsDatumTransform::GridDetails &grid )> &handler );
162 
174  static void setCustomMissingPreferredGridHandler( const std::function< void( const QgsCoordinateReferenceSystem &sourceCrs,
175  const QgsCoordinateReferenceSystem &destinationCrs,
176  const QgsDatumTransform::TransformDetails &preferredOperation,
177  const QgsDatumTransform::TransformDetails &availableOperation )> &handler );
178 
186  static void setCustomCoordinateOperationCreationErrorHandler( const std::function< void( const QgsCoordinateReferenceSystem &sourceCrs,
187  const QgsCoordinateReferenceSystem &destinationCrs,
188  const QString &error )> &handler );
189 
197  static void setCustomMissingGridUsedByContextHandler( const std::function< void( const QgsCoordinateReferenceSystem &sourceCrs,
198  const QgsCoordinateReferenceSystem &destinationCrs,
199  const QgsDatumTransform::TransformDetails &desiredOperation )> &handler );
200 
201  private:
202 
203 #if PROJ_VERSION_MAJOR<6
204  Q_DECL_DEPRECATED QString stripDatumTransform( const QString &proj4 ) const;
206 
208  Q_DECL_DEPRECATED void addNullGridShifts( QString &srcProjString, QString &destProjString, int sourceDatumTransform, int destinationDatumTransform ) const;
209 #endif
210 
211  void freeProj();
212 
213  static std::function< void( const QgsCoordinateReferenceSystem &sourceCrs,
214  const QgsCoordinateReferenceSystem &destinationCrs,
215  const QgsDatumTransform::GridDetails &grid )> sMissingRequiredGridHandler;
216 
217  static std::function< void( const QgsCoordinateReferenceSystem &sourceCrs,
218  const QgsCoordinateReferenceSystem &destinationCrs,
219  const QgsDatumTransform::TransformDetails &preferredOperation,
220  const QgsDatumTransform::TransformDetails &availableOperation )> sMissingPreferredGridHandler;
221 
222  static std::function< void( const QgsCoordinateReferenceSystem &sourceCrs,
223  const QgsCoordinateReferenceSystem &destinationCrs,
224  const QString &error )> sCoordinateOperationCreationErrorHandler;
225 
226  static std::function< void( const QgsCoordinateReferenceSystem &sourceCrs,
227  const QgsCoordinateReferenceSystem &destinationCrs,
228  const QgsDatumTransform::TransformDetails &desiredOperation )> sMissingGridUsedByContextHandler;
229 };
230 
232 
233 #endif // QGSCOORDINATETRANSFORMPRIVATE_H
Contains information about a projection transformation grid file.
Contains information about the context in which a coordinate transform is executed.
This class represents a coordinate reference system (CRS).
Contains information about a coordinate transformation operation.