QGIS API Documentation 4.1.0-Master (60fea48833c)
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:
52 static int projVersionMajor();
53
59 static int projVersionMinor();
60
67 static QString epsgRegistryVersion();
68
75 static QDate epsgRegistryDate();
76
83 static QString esriDatabaseVersion();
84
91 static QDate esriDatabaseDate();
92
99 static QString ignfDatabaseVersion();
100
107 static QDate ignfDatabaseDate();
108
115 static QStringList searchPaths();
116
117#ifndef SIP_RUN
118
124 Q_DECLARE_FLAGS( IdentifyFlags, IdentifyFlag )
125
126
130 {
134 void CORE_EXPORT operator()( PJ *object ) const;
135 };
136
140 using proj_pj_unique_ptr = std::unique_ptr< PJ, ProjPJDeleter >;
141
146 static bool usesAngularUnit( const QString &projDef );
147
148 //TODO - remove when proj 6.1 is minimum supported version, and replace with proj_normalize_for_visualization
149
154 static bool axisOrderIsSwapped( const PJ *crs );
155
164 static bool isDynamic( const PJ *crs );
165
174 static proj_pj_unique_ptr crsToHorizontalCrs( const PJ *crs );
175
186 static proj_pj_unique_ptr crsToVerticalCrs( const PJ *crs );
187
193 static bool hasVerticalAxis( const PJ *crs );
194
201 static proj_pj_unique_ptr unboundCrs( const PJ *crs );
202
210 static proj_pj_unique_ptr crsToDatumEnsemble( const PJ *crs );
211
219 static proj_pj_unique_ptr createCompoundCrs( const PJ *horizontalCrs, const PJ *verticalCrs, QStringList *errors = nullptr );
220
227 static bool identifyCrs( const PJ *crs, QString &authName, QString &authCode, IdentifyFlags flags = IdentifyFlags() );
228
232 static bool coordinateOperationIsAvailable( const QString &projDef );
233
237 static QList< QgsDatumTransform::GridDetails > gridsUsed( const QString &proj );
238
244 static void proj_logger( void *user_data, int level, const char *message );
245
253 static void proj_collecting_logger( void *user_data, int level, const char *message );
254
258 static void proj_silent_logger( void *user_data, int level, const char *message );
259
260#if 0 // not possible in current Proj 6 API
261
266 static QStringList nonAvailableGrids( const QString &projDef );
267#endif
268#endif
269};
270
271#ifndef SIP_RUN
272
273struct pj_ctx;
274typedef struct pj_ctx PJ_CONTEXT;
275
283class CORE_EXPORT QgsProjContext
284{
285 public:
288
292 static PJ_CONTEXT *get();
293
294 private:
295 PJ_CONTEXT *mContext = nullptr;
296
301#if defined( USE_THREAD_LOCAL ) && !defined( Q_OS_WIN )
302 static thread_local QgsProjContext sProjContext;
303#else
304 static QThreadStorage< QgsProjContext * > sProjContext;
305#endif
306};
307
322{
323 public:
330
335};
336
337
352{
353 public:
360
365
369 QStringList errors() const { return mProjErrors; }
370
371 private:
372 QStringList mProjErrors;
373};
374
376#endif
377#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.