QGIS API Documentation  3.10.0-A Coruña (6c816b4204)
qgsprojutils.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsprojutils.h
3  -------------------
4  begin : March 2019
5  copyright : (C) 2019 by 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 QGSPROJUTILS_H
18 #define QGSPROJUTILS_H
19 
20 #include <QtGlobal>
21 
22 #include "qgis_core.h"
23 #include "qgsconfig.h"
24 #include "qgsdatumtransform.h"
25 #include <memory>
26 #include <QStringList>
27 
28 #if !defined(USE_THREAD_LOCAL) || defined(Q_OS_WIN)
29 #include <QThreadStorage>
30 #endif
31 
32 #if PROJ_VERSION_MAJOR>=6
33 #ifndef SIP_RUN
34 struct PJconsts;
35 typedef struct PJconsts PJ;
36 #endif
37 #endif
38 
45 class CORE_EXPORT QgsProjUtils
46 {
47  public:
48 
52  static int projVersionMajor()
53  {
54  return PROJ_VERSION_MAJOR;
55  }
56 
63  static QStringList searchPaths();
64 
65 #ifndef SIP_RUN
66 #if PROJ_VERSION_MAJOR >= 6
67 
71  struct ProjPJDeleter
72  {
73 
77  void CORE_EXPORT operator()( PJ *object );
78 
79  };
80 
84  using proj_pj_unique_ptr = std::unique_ptr< PJ, ProjPJDeleter >;
85 
90  static bool usesAngularUnit( const QString &projDef );
91 
92  //TODO - remove when proj 6.1 is minimum supported version, and replace with proj_normalize_for_visualization
93 
98  static bool axisOrderIsSwapped( const PJ *crs );
99 
104  static proj_pj_unique_ptr crsToSingleCrs( const PJ *crs );
105 
109  static bool coordinateOperationIsAvailable( const QString &projDef );
110 
114  static QList< QgsDatumTransform::GridDetails > gridsUsed( const QString &proj );
115 
116 
117 #if 0 // not possible in current Proj 6 API
118 
123  static QStringList nonAvailableGrids( const QString &projDef );
124 #endif
125 #endif
126 #endif
127 };
128 
129 #ifndef SIP_RUN
130 
131 #if PROJ_VERSION_MAJOR>=6
132 struct projCtx_t;
133 typedef struct projCtx_t PJ_CONTEXT;
134 #else
135 typedef void PJ_CONTEXT;
136 #endif
137 
145 class CORE_EXPORT QgsProjContext
146 {
147  public:
148 
149  QgsProjContext();
150  ~QgsProjContext();
151 
155  static PJ_CONTEXT *get();
156 
157  private:
158  PJ_CONTEXT *mContext = nullptr;
159 
164 #if defined(USE_THREAD_LOCAL) && !defined(Q_OS_WIN)
165  static thread_local QgsProjContext sProjContext;
166 #else
167  static QThreadStorage< QgsProjContext * > sProjContext;
168 #endif
169 };
170 
171 #endif
172 #endif // QGSPROJUTILS_H
static int projVersionMajor()
Returns the proj library major version number.
Definition: qgsprojutils.h:52
const QgsCoordinateReferenceSystem & crs
Used to create and store a proj context object, correctly freeing the context upon destruction...
Definition: qgsprojutils.h:145
void PJ_CONTEXT
Definition: qgsprojutils.h:135
Utility functions for working with the proj library.
Definition: qgsprojutils.h:45