QGIS API Documentation  3.18.1-Zürich (202f1bf7e5)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 
60  static QStringList searchPaths();
61 
62 #ifndef SIP_RUN
63 
66  {
67  FlagMatchBoundCrsToUnderlyingSourceCrs = 1 << 0,
68  };
69  Q_DECLARE_FLAGS( IdentifyFlags, IdentifyFlag )
70 
71 #if PROJ_VERSION_MAJOR >= 6
72 
76  struct ProjPJDeleter
77  {
78 
82  void CORE_EXPORT operator()( PJ *object );
83 
84  };
85 
89  using proj_pj_unique_ptr = std::unique_ptr< PJ, ProjPJDeleter >;
90 
95  static bool usesAngularUnit( const QString &projDef );
96 
97  //TODO - remove when proj 6.1 is minimum supported version, and replace with proj_normalize_for_visualization
98 
103  static bool axisOrderIsSwapped( const PJ *crs );
104 
109  static proj_pj_unique_ptr crsToSingleCrs( const PJ *crs );
110 
117  static bool identifyCrs( const PJ *crs, QString &authName, QString &authCode, IdentifyFlags flags = IdentifyFlags() );
118 
122  static bool coordinateOperationIsAvailable( const QString &projDef );
123 
127  static QList< QgsDatumTransform::GridDetails > gridsUsed( const QString &proj );
128 
129 
130 #if 0 // not possible in current Proj 6 API
131 
136  static QStringList nonAvailableGrids( const QString &projDef );
137 #endif
138 #endif
139 #endif
140 };
141 
142 #ifndef SIP_RUN
143 
144 #if PROJ_VERSION_MAJOR>=8
145 struct pj_ctx;
146 typedef struct pj_ctx PJ_CONTEXT;
147 #elif PROJ_VERSION_MAJOR>=6
148 struct projCtx_t;
149 typedef struct projCtx_t PJ_CONTEXT;
150 #else
151 typedef void PJ_CONTEXT;
152 #endif
153 
161 class CORE_EXPORT QgsProjContext
162 {
163  public:
164 
165  QgsProjContext();
166  ~QgsProjContext();
167 
171  static PJ_CONTEXT *get();
172 
173  private:
174  PJ_CONTEXT *mContext = nullptr;
175 
180 #if defined(USE_THREAD_LOCAL) && !defined(Q_OS_WIN)
181  static thread_local QgsProjContext sProjContext;
182 #else
183  static QThreadStorage< QgsProjContext * > sProjContext;
184 #endif
185 };
186 
187 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsProjUtils::IdentifyFlags )
188 #endif
189 #endif // QGSPROJUTILS_H
Used to create and store a proj context object, correctly freeing the context upon destruction.
Definition: qgsprojutils.h:162
Utility functions for working with the proj library.
Definition: qgsprojutils.h:46
IdentifyFlag
Flags controlling CRS identification behavior.
Definition: qgsprojutils.h:66
Q_DECLARE_OPERATORS_FOR_FLAGS(QgsField::ConfigurationFlags) CORE_EXPORT QDataStream &operator<<(QDataStream &out
Writes the field to stream out. QGIS version compatibility is not guaranteed.
void PJ_CONTEXT
Definition: qgsprojutils.h:151
const QgsCoordinateReferenceSystem & crs