QGIS API Documentation  3.8.0-Zanzibar (11aff65)
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 
109  bool mIsValid = false;
110 
115  bool mShortCircuit = false;
116 
118  QgsCoordinateReferenceSystem mSourceCRS;
119 
122 
123  Q_DECL_DEPRECATED QString mSourceProjString;
124  Q_DECL_DEPRECATED QString mDestProjString;
125 
126  Q_DECL_DEPRECATED int mSourceDatumTransform = -1;
127  Q_DECL_DEPRECATED int mDestinationDatumTransform = -1;
128  QString mProjCoordinateOperation;
129 
130 #if PROJ_VERSION_MAJOR<6
131 
136 #ifdef USE_THREAD_LOCAL
137  static thread_local QgsProjContextStore mProjContext;
138 #else
139  static QThreadStorage< QgsProjContextStore * > mProjContext;
140 #endif
141 #endif
142 
143 
144  QReadWriteLock mProjLock;
145  QMap < uintptr_t, ProjData > mProjProjections;
146 
154  static void setCustomMissingRequiredGridHandler( const std::function< void( const QgsCoordinateReferenceSystem &sourceCrs,
155  const QgsCoordinateReferenceSystem &destinationCrs,
156  const QgsDatumTransform::GridDetails &grid )> &handler );
157 
169  static void setCustomMissingPreferredGridHandler( const std::function< void( const QgsCoordinateReferenceSystem &sourceCrs,
170  const QgsCoordinateReferenceSystem &destinationCrs,
171  const QgsDatumTransform::TransformDetails &preferredOperation,
172  const QgsDatumTransform::TransformDetails &availableOperation )> &handler );
173 
181  static void setCustomCoordinateOperationCreationErrorHandler( const std::function< void( const QgsCoordinateReferenceSystem &sourceCrs,
182  const QgsCoordinateReferenceSystem &destinationCrs,
183  const QString &error )> &handler );
184 
192  static void setCustomMissingGridUsedByContextHandler( const std::function< void( const QgsCoordinateReferenceSystem &sourceCrs,
193  const QgsCoordinateReferenceSystem &destinationCrs,
194  const QgsDatumTransform::TransformDetails &desiredOperation )> &handler );
195 
196  private:
197 
198 #if PROJ_VERSION_MAJOR<6
199  Q_DECL_DEPRECATED QString stripDatumTransform( const QString &proj4 ) const;
201 
203  Q_DECL_DEPRECATED void addNullGridShifts( QString &srcProjString, QString &destProjString, int sourceDatumTransform, int destinationDatumTransform ) const;
204 #endif
205 
206  void freeProj();
207 
208  static std::function< void( const QgsCoordinateReferenceSystem &sourceCrs,
209  const QgsCoordinateReferenceSystem &destinationCrs,
210  const QgsDatumTransform::GridDetails &grid )> sMissingRequiredGridHandler;
211 
212  static std::function< void( const QgsCoordinateReferenceSystem &sourceCrs,
213  const QgsCoordinateReferenceSystem &destinationCrs,
214  const QgsDatumTransform::TransformDetails &preferredOperation,
215  const QgsDatumTransform::TransformDetails &availableOperation )> sMissingPreferredGridHandler;
216 
217  static std::function< void( const QgsCoordinateReferenceSystem &sourceCrs,
218  const QgsCoordinateReferenceSystem &destinationCrs,
219  const QString &error )> sCoordinateOperationCreationErrorHandler;
220 
221  static std::function< void( const QgsCoordinateReferenceSystem &sourceCrs,
222  const QgsCoordinateReferenceSystem &destinationCrs,
223  const QgsDatumTransform::TransformDetails &desiredOperation )> sMissingGridUsedByContextHandler;
224 };
225 
227 
228 #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.