Skip to content

Commit

Permalink
Add support for PROJ_AUX_DB environment variable to set the path to o…
Browse files Browse the repository at this point in the history
…ne or several auxiliary DBs
  • Loading branch information
rouault committed Mar 15, 2021
1 parent c96abdc commit 51f5230
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 6 deletions.
12 changes: 12 additions & 0 deletions docs/source/usage/environmentvars.rst
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,18 @@ done by setting the variable with no content::
:envvar:`PROJ_LIB` to allow for multiple versions of PROJ
resource files on your system without conflicting.


.. envvar:: PROJ_AUX_DB

.. versionadded:: 8.1.0

To set the path to one or several auxiliary SQLite3 databases of structure
identical to the main ``proj.db`` database and that can contain additional
object (CRS, transformation, ...) definitions. If several paths are
provided, they must be separated by the colon (:) character on Unix, and
on Windows, by the semi-colon (;) character.


.. envvar:: PROJ_DEBUG

Set the debug level of PROJ. The default debug level is zero, which results
Expand Down
9 changes: 6 additions & 3 deletions src/ctx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,16 @@ pj_ctx pj_ctx::createDefault()
ctx.logger = pj_stderr_logger;
NS_PROJ::FileManager::fillDefaultNetworkInterface(&ctx);

if( getenv("PROJ_DEBUG") != nullptr )
const char* projDebug = getenv("PROJ_DEBUG");
if( projDebug != nullptr )
{
if( atoi(getenv("PROJ_DEBUG")) >= -PJ_LOG_TRACE )
ctx.debug_level = atoi(getenv("PROJ_DEBUG"));
const int debugLevel = atoi(projDebug);
if( debugLevel >= -PJ_LOG_TRACE )
ctx.debug_level = debugLevel;
else
ctx.debug_level = PJ_LOG_TRACE;
}

return ctx;
}

Expand Down
23 changes: 20 additions & 3 deletions src/iso19111/factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2482,6 +2482,11 @@ DatabaseContext::DatabaseContext() : d(internal::make_unique<Private>()) {}
* string for the default rules to locate the default proj.db
* @param auxiliaryDatabasePaths Path and filename of auxiliary databases.
* Might be empty.
* Starting with PROJ 8.1, if this parameter is an empty array,
* the PROJ_AUX_DB environment variable will be used, if set.
* It must contain one or several paths. If several paths are
* provided, they must be separated by the colon (:) character on Unix, and
* on Windows, by the semi-colon (;) character.
* @param ctx Context used for file search.
* @throw FactoryException
*/
Expand All @@ -2493,9 +2498,21 @@ DatabaseContext::create(const std::string &databasePath,
auto dbCtxPrivate = dbCtx->getPrivate();
dbCtxPrivate->open(databasePath, ctx);
dbCtxPrivate->checkDatabaseLayout(databasePath, std::string());
if (!auxiliaryDatabasePaths.empty()) {
dbCtxPrivate->attachExtraDatabases(auxiliaryDatabasePaths);
dbCtxPrivate->auxiliaryDatabasePaths_ = auxiliaryDatabasePaths;
auto auxDbs(auxiliaryDatabasePaths);
if (auxDbs.empty()) {
const char *auxDbStr = getenv("PROJ_AUX_DB");
if (auxDbStr) {
#ifdef _WIN32
const char *delim = ";";
#else
const char *delim = ":";
#endif
auxDbs = split(auxDbStr, delim);
}
}
if (!auxDbs.empty()) {
dbCtxPrivate->attachExtraDatabases(auxDbs);
dbCtxPrivate->auxiliaryDatabasePaths_ = auxDbs;
}
dbCtxPrivate->self_ = dbCtx.as_nullable();
return dbCtx;
Expand Down
9 changes: 9 additions & 0 deletions test/cli/testprojinfo
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,15 @@ echo "Testing projinfo --dump-db-structure --output-id HOBU:XXXX EPSG:4326 | tai
$EXE --dump-db-structure --output-id HOBU:XXXX EPSG:4326 | tail -n 4 >>${OUT}
echo "" >>${OUT}

echo "Testing PROJ_AUX_DB environment variable" >> ${OUT}
rm -f tmp_projinfo_aux.db
$EXE --dump-db-structure --output-id HOBU:XXXX EPSG:4326 | sqlite3 tmp_projinfo_aux.db
export PROJ_AUX_DB=tmp_projinfo_aux.db
$EXE HOBU:XXXX >>${OUT}
unset PROJ_AUX_DB
rm -f tmp_projinfo_aux.db
echo "" >>${OUT}

# do 'diff' with distribution results
echo "diff ${OUT} with testprojinfo_out.dist"
diff -u ${OUT} ${TEST_CLI_DIR}/testprojinfo_out.dist
Expand Down
31 changes: 31 additions & 0 deletions test/cli/testprojinfo_out.dist
Original file line number Diff line number Diff line change
Expand Up @@ -1559,3 +1559,34 @@ INSERT INTO metadata VALUES('DATABASE.LAYOUT.VERSION.MINOR',0);
INSERT INTO geodetic_crs VALUES('HOBU','XXXX','WGS 84','','geographic 2D','EPSG','6422','EPSG','6326',NULL,0);
INSERT INTO usage VALUES('HOBU','USAGE_GEODETIC_CRS_XXXX','geodetic_crs','HOBU','XXXX','EPSG','1262','EPSG','1183');

Testing PROJ_AUX_DB environment variable
PROJ.4 string:
+proj=longlat +datum=WGS84 +no_defs +type=crs

WKT2:2019 string:
GEOGCRS["WGS 84",
ENSEMBLE["World Geodetic System 1984 ensemble",
MEMBER["World Geodetic System 1984 (Transit)"],
MEMBER["World Geodetic System 1984 (G730)"],
MEMBER["World Geodetic System 1984 (G873)"],
MEMBER["World Geodetic System 1984 (G1150)"],
MEMBER["World Geodetic System 1984 (G1674)"],
MEMBER["World Geodetic System 1984 (G1762)"],
ELLIPSOID["WGS 84",6378137,298.257223563,
LENGTHUNIT["metre",1]],
ENSEMBLEACCURACY[2.0]],
PRIMEM["Greenwich",0,
ANGLEUNIT["degree",0.0174532925199433]],
CS[ellipsoidal,2],
AXIS["geodetic latitude (Lat)",north,
ORDER[1],
ANGLEUNIT["degree",0.0174532925199433]],
AXIS["geodetic longitude (Lon)",east,
ORDER[2],
ANGLEUNIT["degree",0.0174532925199433]],
USAGE[
SCOPE["Horizontal component of 3D system."],
AREA["World."],
BBOX[-90,-180,90,180]],
ID["HOBU","XXXX"]]

0 comments on commit 51f5230

Please sign in to comment.