/
qgsprojutils.h
230 lines (192 loc) · 6.36 KB
/
qgsprojutils.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
/***************************************************************************
qgsprojutils.h
-------------------
begin : March 2019
copyright : (C) 2019 by Nyall Dawson
email : nyall dot dawson at gmail dot com
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef QGSPROJUTILS_H
#define QGSPROJUTILS_H
#include <QtGlobal>
#include "qgis_core.h"
#include "qgsconfig.h"
#include "qgsdatumtransform.h"
#include <memory>
#include <QStringList>
#if !defined(USE_THREAD_LOCAL) || defined(Q_OS_WIN)
#include <QThreadStorage>
#endif
#ifndef SIP_RUN
struct PJconsts;
typedef struct PJconsts PJ;
#endif
/**
* \class QgsProjUtils
* \ingroup core
* \brief Utility functions for working with the proj library.
* \since QGIS 3.8
*/
class CORE_EXPORT QgsProjUtils
{
public:
/**
* Returns the proj library major version number.
*/
static int projVersionMajor();
/**
* Returns the EPSG registry database version used by the proj library (e.g. "v9.8.6").
*
* \see epsgRegistryDate()
* \since QGIS 3.20
*/
static QString epsgRegistryVersion();
/**
* Returns the EPSG registry database release date used by the proj library.
*
* \see epsgRegistryVersion()
* \since QGIS 3.20
*/
static QDate epsgRegistryDate();
/**
* Returns the ESRI projection engine database version used by the proj library (e.g. "ArcMap 10.8.0").
*
* \see esriDatabaseDate()
* \since QGIS 3.20
*/
static QString esriDatabaseVersion();
/**
* Returns the ESRI projection engine database release date used by the proj library.
*
* \see esriDatabaseVersion()
* \since QGIS 3.20
*/
static QDate esriDatabaseDate();
/**
* Returns the IGNF database version used by the proj library (e.g. "3.1.0").
*
* \see ignfDatabaseDate()
* \since QGIS 3.20
*/
static QString ignfDatabaseVersion();
/**
* Returns the IGNF database release date used by the proj library.
*
* \see ignfDatabaseVersion()
* \since QGIS 3.20
*/
static QDate ignfDatabaseDate();
/**
* Returns the current list of Proj file search paths.
*
* \note Only available on builds based on Proj >= 6.0. Builds based on
* earlier Proj versions will always return an empty list.
*/
static QStringList searchPaths();
#ifndef SIP_RUN
//! Flags controlling CRS identification behavior
enum IdentifyFlag
{
FlagMatchBoundCrsToUnderlyingSourceCrs = 1 << 0, //!< Allow matching a BoundCRS object to its underlying SourceCRS
};
Q_DECLARE_FLAGS( IdentifyFlags, IdentifyFlag )
/**
* Destroys Proj PJ objects.
*/
struct ProjPJDeleter
{
/**
* Destroys an PJ \a object, using the correct proj calls.
*/
void CORE_EXPORT operator()( PJ *object );
};
/**
* Scoped Proj PJ object.
*/
using proj_pj_unique_ptr = std::unique_ptr< PJ, ProjPJDeleter >;
/**
* Returns TRUE if the given proj coordinate system uses angular units. \a projDef must be
* a proj string defining a CRS object.
*/
static bool usesAngularUnit( const QString &projDef );
//TODO - remove when proj 6.1 is minimum supported version, and replace with proj_normalize_for_visualization
/**
* Returns TRUE if the given proj coordinate system uses requires y/x coordinate
* order instead of x/y.
*/
static bool axisOrderIsSwapped( const PJ *crs );
/**
* Given a PROJ crs (which may be a compound or bound crs, or some other type), extract a single crs
* from it.
*/
static proj_pj_unique_ptr crsToSingleCrs( const PJ *crs );
/**
* Attempts to identify a \a crs, matching it to a known authority and code within
* an acceptable level of tolerance.
*
* Returns TRUE if a matching authority and code was found.
*/
static bool identifyCrs( const PJ *crs, QString &authName, QString &authCode, IdentifyFlags flags = IdentifyFlags() );
/**
* Returns TRUE if a coordinate operation (specified via proj string) is available.
*/
static bool coordinateOperationIsAvailable( const QString &projDef );
/**
* Returns a list of grids used by the given \a proj string.
*/
static QList< QgsDatumTransform::GridDetails > gridsUsed( const QString &proj );
#if 0 // not possible in current Proj 6 API
/**
* Given a coordinate operation (specified via proj string), returns a list of
* any required grids which are not currently available for use.
*/
static QStringList nonAvailableGrids( const QString &projDef );
#endif
#endif
};
#ifndef SIP_RUN
#if PROJ_VERSION_MAJOR>=8
struct pj_ctx;
typedef struct pj_ctx PJ_CONTEXT;
#else
struct projCtx_t;
typedef struct projCtx_t PJ_CONTEXT;
#endif
/**
* \class QgsProjContext
* \ingroup core
* \brief Used to create and store a proj context object, correctly freeing the context upon destruction.
* \note Not available in Python bindings
* \since QGIS 3.8
*/
class CORE_EXPORT QgsProjContext
{
public:
QgsProjContext();
~QgsProjContext();
/**
* Returns a thread local instance of a proj context, safe for use in the current thread.
*/
static PJ_CONTEXT *get();
private:
PJ_CONTEXT *mContext = nullptr;
/**
* Thread local proj context storage. A new proj context will be created
* for every thread.
*/
#if defined(USE_THREAD_LOCAL) && !defined(Q_OS_WIN)
static thread_local QgsProjContext sProjContext;
#else
static QThreadStorage< QgsProjContext * > sProjContext;
#endif
};
Q_DECLARE_OPERATORS_FOR_FLAGS( QgsProjUtils::IdentifyFlags )
#endif
#endif // QGSPROJUTILS_H