File tree Expand file tree Collapse file tree 5 files changed +79
-0
lines changed
python/core/auto_generated Expand file tree Collapse file tree 5 files changed +79
-0
lines changed Original file line number Diff line number Diff line change @@ -29,6 +29,16 @@ Utility functions for working with the proj library.
29
29
Returns the proj library major version number.
30
30
%End
31
31
32
+ static QStringList searchPaths();
33
+ %Docstring
34
+ Returns the current list of Proj file search paths.
35
+
36
+ .. note::
37
+
38
+ Only available on builds based on Proj >= 6.0. Builds based on
39
+ earlier Proj versions will always return an empty list.
40
+ %End
41
+
32
42
};
33
43
34
44
/************************************************************************
Original file line number Diff line number Diff line change 51
51
#include " qgslayoutrendercontext.h"
52
52
#include " qgssqliteutils.h"
53
53
#include " qgsstyle.h"
54
+ #include " qgsprojutils.h"
54
55
#include " qgsvaliditycheckregistry.h"
55
56
56
57
#include " gps/qgsgpsconnectionregistry.h"
91
92
#include < cpl_conv.h> // for setting gdal options
92
93
#include < sqlite3.h>
93
94
95
+ #if PROJ_VERSION_MAJOR>=6
96
+ #include < proj.h>
97
+ #endif
98
+
99
+
94
100
#define CONN_POOL_MAX_CONCURRENT_CONNS 4
95
101
96
102
QObject *ABISYM ( QgsApplication::mFileOpenEventReceiver );
@@ -295,6 +301,20 @@ void QgsApplication::init( QString profileFolder )
295
301
}
296
302
ABISYM ( mSystemEnvVars ) = systemEnvVarMap;
297
303
304
+ #if PROJ_VERSION_MAJOR>=6
305
+ // append local user-writable folder as a proj search path
306
+ QStringList currentProjSearchPaths = QgsProjUtils::searchPaths ();
307
+ currentProjSearchPaths.append ( qgisSettingsDirPath () + QStringLiteral ( " proj" ) );
308
+ const char **newPaths = new const char *[currentProjSearchPaths.length ()];
309
+ for ( int i = 0 ; i < currentProjSearchPaths.count (); ++i )
310
+ {
311
+ newPaths[i] = currentProjSearchPaths.at ( i ).toUtf8 ().constData ();
312
+ }
313
+ proj_context_set_search_paths ( nullptr , currentProjSearchPaths.count (), newPaths );
314
+ delete [] newPaths;
315
+ #endif
316
+
317
+
298
318
// allow Qt to search for Qt plugins (e.g. sqldrivers) in our plugin directory
299
319
QCoreApplication::addLibraryPath ( pluginPath () );
300
320
Original file line number Diff line number Diff line change 15
15
* *
16
16
***************************************************************************/
17
17
#include " qgsprojutils.h"
18
+ #include " qgis.h"
18
19
#include < QString>
20
+ #include < QSet>
19
21
20
22
#if PROJ_VERSION_MAJOR>=6
21
23
#include < proj.h>
@@ -215,3 +217,32 @@ QStringList QgsProjUtils::nonAvailableGrids( const QString &projDef )
215
217
216
218
#endif
217
219
220
+ QStringList QgsProjUtils::searchPaths ()
221
+ {
222
+ #if PROJ_VERSION_MAJOR >= 6
223
+ const QString path ( proj_info ().searchpath );
224
+ QStringList paths;
225
+ // #ifdef Q_OS_WIN
226
+ #if 1 // -- see https://github.com/OSGeo/proj.4/pull/1497
227
+ paths = path.split ( ' ;' );
228
+ #else
229
+ paths = path.split( ':' );
230
+ #endif
231
+
232
+ QSet<QString> existing;
233
+ // thin out duplicates from paths -- see https://github.com/OSGeo/proj.4/pull/1498
234
+ QStringList res;
235
+ res.reserve ( paths.count () );
236
+ for ( const QString &p : qgis::as_const ( paths ) )
237
+ {
238
+ if ( existing.contains ( p ) )
239
+ continue ;
240
+
241
+ existing.insert ( p );
242
+ res << p;
243
+ }
244
+ return res;
245
+ #else
246
+ return QStringList ();
247
+ #endif
248
+ }
Original file line number Diff line number Diff line change @@ -53,6 +53,14 @@ class CORE_EXPORT QgsProjUtils
53
53
return PROJ_VERSION_MAJOR;
54
54
}
55
55
56
+ /* *
57
+ * Returns the current list of Proj file search paths.
58
+ *
59
+ * \note Only available on builds based on Proj >= 6.0. Builds based on
60
+ * earlier Proj versions will always return an empty list.
61
+ */
62
+ static QStringList searchPaths ();
63
+
56
64
#ifndef SIP_RUN
57
65
#if PROJ_VERSION_MAJOR >= 6
58
66
Original file line number Diff line number Diff line change @@ -35,6 +35,7 @@ class TestQgsProjUtils: public QObject
35
35
void threadSafeContext ();
36
36
void usesAngularUnits ();
37
37
void axisOrderIsSwapped ();
38
+ void searchPath ();
38
39
39
40
};
40
41
@@ -97,5 +98,14 @@ void TestQgsProjUtils::axisOrderIsSwapped()
97
98
#endif
98
99
}
99
100
101
+ void TestQgsProjUtils::searchPath ()
102
+ {
103
+ #if PROJ_VERSION_MAJOR>=6
104
+ // ensure local user-writable path is present in Proj search paths
105
+ const QStringList paths = QgsProjUtils::searchPaths ();
106
+ QVERIFY ( paths.contains ( QgsApplication::qgisSettingsDirPath () + QStringLiteral ( " proj" ) ) );
107
+ #endif
108
+ }
109
+
100
110
QGSTEST_MAIN ( TestQgsProjUtils )
101
111
#include " testqgsprojutils.moc"
You can’t perform that action at this time.
0 commit comments