QGIS API Documentation 3.99.0-Master (2fe06baccd8)
Loading...
Searching...
No Matches
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 "qgsconfig.h"
21
22#include <memory>
23
24#include "qgis_core.h"
25#include "qgis_sip.h"
26#include "qgsdatumtransform.h"
27
28#include <QStringList>
29#include <QtGlobal>
30
31#if !defined(USE_THREAD_LOCAL) || defined(Q_OS_WIN)
32#include <QThreadStorage>
33#endif
34
35#ifndef SIP_RUN
36struct PJconsts;
37typedef struct PJconsts PJ;
38#endif
39
46class CORE_EXPORT QgsProjUtils
47{
48 public:
49
53 static int projVersionMajor();
54
60 static int projVersionMinor();
61
68 static QString epsgRegistryVersion();
69
76 static QDate epsgRegistryDate();
77
84 static QString esriDatabaseVersion();
85
92 static QDate esriDatabaseDate();
93
100 static QString ignfDatabaseVersion();
101
108 static QDate ignfDatabaseDate();
109
116 static QStringList searchPaths();
117
118#ifndef SIP_RUN
119
125 Q_DECLARE_FLAGS( IdentifyFlags, IdentifyFlag )
126
127
131 {
132
136 void CORE_EXPORT operator()( PJ *object ) const;
137
138 };
139
143 using proj_pj_unique_ptr = std::unique_ptr< PJ, ProjPJDeleter >;
144
149 static bool usesAngularUnit( const QString &projDef );
150
151 //TODO - remove when proj 6.1 is minimum supported version, and replace with proj_normalize_for_visualization
152
157 static bool axisOrderIsSwapped( const PJ *crs );
158
167 static bool isDynamic( const PJ *crs );
168
177 static proj_pj_unique_ptr crsToHorizontalCrs( const PJ *crs );
178
189 static proj_pj_unique_ptr crsToVerticalCrs( const PJ *crs );
190
196 static bool hasVerticalAxis( const PJ *crs );
197
204 static proj_pj_unique_ptr unboundCrs( const PJ *crs );
205
213 static proj_pj_unique_ptr crsToDatumEnsemble( const PJ *crs );
214
222 static proj_pj_unique_ptr createCompoundCrs( const PJ *horizontalCrs, const PJ *verticalCrs, QStringList *errors = nullptr );
223
230 static bool identifyCrs( const PJ *crs, QString &authName, QString &authCode, IdentifyFlags flags = IdentifyFlags() );
231
235 static bool coordinateOperationIsAvailable( const QString &projDef );
236
240 static QList< QgsDatumTransform::GridDetails > gridsUsed( const QString &proj );
241
247 static void proj_logger( void *user_data, int level, const char *message );
248
256 static void proj_collecting_logger( void *user_data, int level, const char *message );
257
261 static void proj_silent_logger( void *user_data, int level, const char *message );
262
263#if 0 // not possible in current Proj 6 API
264
269 static QStringList nonAvailableGrids( const QString &projDef );
270#endif
271#endif
272};
273
274#ifndef SIP_RUN
275
276struct pj_ctx;
277typedef struct pj_ctx PJ_CONTEXT;
278
286class CORE_EXPORT QgsProjContext
287{
288 public:
289
292
296 static PJ_CONTEXT *get();
297
298 private:
299 PJ_CONTEXT *mContext = nullptr;
300
305#if defined(USE_THREAD_LOCAL) && !defined(Q_OS_WIN)
306 static thread_local QgsProjContext sProjContext;
307#else
308 static QThreadStorage< QgsProjContext * > sProjContext;
309#endif
310};
311
326{
327 public:
328
335
340
341};
342
343
344
359{
360 public:
361
368
373
377 QStringList errors() const { return mProjErrors; }
378
379 private:
380
381 QStringList mProjErrors;
382};
383
385#endif
386#endif // QGSPROJUTILS_H
static PJ_CONTEXT * get()
Returns a thread local instance of a proj context, safe for use in the current thread.
Utility functions for working with the proj library.
static proj_pj_unique_ptr crsToHorizontalCrs(const PJ *crs)
Given a PROJ crs (which may be a compound or bound crs, or some other type), extract the horizontal c...
IdentifyFlag
Flags controlling CRS identification behavior.
@ FlagMatchBoundCrsToUnderlyingSourceCrs
Allow matching a BoundCRS object to its underlying SourceCRS.
static QList< QgsDatumTransform::GridDetails > gridsUsed(const QString &proj)
Returns a list of grids used by the given proj string.
static proj_pj_unique_ptr createCompoundCrs(const PJ *horizontalCrs, const PJ *verticalCrs, QStringList *errors=nullptr)
Given a PROJ horizontal and vertical CRS, attempt to create a compound CRS from them.
static bool isDynamic(const PJ *crs)
Returns true if the given proj coordinate system is a dynamic CRS.
static QDate epsgRegistryDate()
Returns the EPSG registry database release date used by the proj library.
static proj_pj_unique_ptr unboundCrs(const PJ *crs)
Given a PROJ crs (which may be a compound or bound crs, or some other type), ensure that it is not a ...
static bool identifyCrs(const PJ *crs, QString &authName, QString &authCode, IdentifyFlags flags=IdentifyFlags())
Attempts to identify a crs, matching it to a known authority and code within an acceptable level of t...
static QStringList searchPaths()
Returns the current list of Proj file search paths.
static bool hasVerticalAxis(const PJ *crs)
Returns true if a PROJ crs has a vertical axis.
static proj_pj_unique_ptr crsToVerticalCrs(const PJ *crs)
Given a PROJ crs (which may be a compound crs, or some other type), extract the vertical crs from it.
static QString ignfDatabaseVersion()
Returns the IGNF database version used by the proj library (e.g.
static proj_pj_unique_ptr crsToDatumEnsemble(const PJ *crs)
Given a PROJ crs, attempt to retrieve the datum ensemble from it.
static void proj_collecting_logger(void *user_data, int level, const char *message)
QGIS proj log function which collects errors to a QStringList.
QFlags< IdentifyFlag > IdentifyFlags
static void proj_logger(void *user_data, int level, const char *message)
Default QGIS proj log function.
static bool coordinateOperationIsAvailable(const QString &projDef)
Returns true if a coordinate operation (specified via proj string) is available.
static QString epsgRegistryVersion()
Returns the EPSG registry database version used by the proj library (e.g.
static QDate esriDatabaseDate()
Returns the ESRI projection engine database release date used by the proj library.
static void proj_silent_logger(void *user_data, int level, const char *message)
QGIS proj log function which ignores errors.
std::unique_ptr< PJ, ProjPJDeleter > proj_pj_unique_ptr
Scoped Proj PJ object.
static bool usesAngularUnit(const QString &projDef)
Returns true if the given proj coordinate system uses angular units.
static bool axisOrderIsSwapped(const PJ *crs)
Returns true if the given proj coordinate system uses requires y/x coordinate order instead of x/y.
static QString esriDatabaseVersion()
Returns the ESRI projection engine database version used by the proj library (e.g.
static int projVersionMajor()
Returns the proj library major version number.
static QDate ignfDatabaseDate()
Returns the IGNF database release date used by the proj library.
static int projVersionMinor()
Returns the proj library minor version number.
QStringList errors() const
Returns the (possibly empty) list of collected errors.
QgsScopedProjCollectingLogger()
Constructor for QgsScopedProjCollectingLogger.
QgsScopedProjSilentLogger()
Constructor for QgsScopedProjSilentLogger.
struct pj_ctx PJ_CONTEXT
struct PJconsts PJ
Q_DECLARE_OPERATORS_FOR_FLAGS(QgsProjectionSelectionWidget::CrsOptions)
Destroys Proj PJ objects.
void CORE_EXPORT operator()(PJ *object) const
Destroys an PJ object, using the correct proj calls.