Re: How to find the active metadata search path in PROJ 6
Roger Bivand <[email protected]>
| Newsgroups | gmane.comp.gis.proj-4.devel |
|---|---|
| Message-ID | <[email protected]> |
On Sun, 8 Sep 2019, Nyall Dawson wrote: > On Sat, 7 Sep 2019 at 23:20, Roger Bivand <[email protected]> wrote: > xample >> holding grid files downloaded on the fly or caches from previous sessions, >> and where the default data/ directory is not user-writable, > > Good move, I think all proj based end-user applications should also > implement this logic. It does seem justified, doesn't it? It might be even more sensible if (at some time in the future) the user-writable cache directory was shared between applications, so that different R or Python packages or QGIS etc. didn't each have to have separate dumps of the same grid files ... just speculating. > >> I think I need >> to build the ":" or ";" separated list to update the search path. To avoid >> overwriting it, I need to prepend the active search path to the local >> user-writable directory. >> >> Hope this is just something I've missed, a function returning a string, or >> equivalent mechanism. > > Here's how we do it in QGIS. Excuse the mix of pure c++/proj/qt api (a > necessary by-product of working in QGIS code): > > on startup: > > // append local user-writable folder as a proj search path > QStringList currentProjSearchPaths = QgsProjUtils::searchPaths(); > currentProjSearchPaths.append( qgisSettingsDirPath() + "proj" ); > char **newPaths = new char *[currentProjSearchPaths.length()]; > for ( int i = 0; i < currentProjSearchPaths.count(); ++i ) > { > newPaths[i] = CPLStrdup( currentProjSearchPaths.at( i > ).toUtf8().constData() ); > } > proj_context_set_search_paths( nullptr, > currentProjSearchPaths.count(), newPaths ); > for ( int i = 0; i < currentProjSearchPaths.count(); ++i ) > { > CPLFree( newPaths[i] ); > } > delete [] newPaths; > > where QgsProjUtils::searchPaths() is: > > QStringList QgsProjUtils::searchPaths() > { > const QString path( proj_info().searchpath ); This: ^^^^^^^^^^^^^^^^^^^^^ was what I needed for a first prototype, thanks very much! I'd missed this because I didn't read the PROJ_INFO struct definition in proj.h (starting line 273 in the 6.2.0 source). > QStringList paths; > #if PROJ_VERSION_MINOR==1 && PROJ_VERSION_PATCH==0 > // -- see https://github.com/OSGeo/proj.4/pull/1497 > paths = path.split( ';' ); > #else > #ifdef Q_OS_WIN > paths = path.split( ';' ); > #else > paths = path.split( ':' ); > #endif > #endif > QSet<QString> existing; > // thin out duplicates from paths -- see > https://github.com/OSGeo/proj.4/pull/1498 > QStringList res; > res.reserve( paths.count() ); > for ( const QString &p : qgis::as_const( paths ) ) > { > if ( existing.contains( p ) ) > continue; > existing.insert( p ); > res << p; > } > return res; > } > > There's quite a bit of logic here which is in place to work around > earlier PROJ 6 release behavior, see the links commented in the code > above. Thanks again, Roger > > Nyall > > >> >> Roger >> >> -- >> Roger Bivand >> Department of Economics, Norwegian School of Economics, >> Helleveien 30, N-5045 Bergen, Norway. >> voice: +47 55 95 93 55; e-mail: [email protected] >> https://orcid.org/0000-0003-2392-6140 >> https://scholar.google.no/citations?user=AWeghB0AAAAJ&hl=en >> _______________________________________________ >> PROJ mailing list >> [email protected] >> https://lists.osgeo.org/mailman/listinfo/proj > -- Roger Bivand Department of Economics, Norwegian School of Economics, Helleveien 30, N-5045 Bergen, Norway. voice: +47 55 95 93 55; e-mail: [email protected] https://orcid.org/0000-0003-2392-6140 https://scholar.google.no/citations?user=AWeghB0AAAAJ&hl=en _______________________________________________ PROJ mailing list [email protected] https://lists.osgeo.org/mailman/listinfo/proj