From 15d6475b8caeb169fd2c060076738db75fc527b3 Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Mon, 19 Aug 2019 20:57:07 +0200 Subject: C API: add proj_context_set_autoclose_database() to automatically close database (fixes #1565) --- src/4D_api.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'src/4D_api.cpp') diff --git a/src/4D_api.cpp b/src/4D_api.cpp index 9f445d88..07ccfd91 100644 --- a/src/4D_api.cpp +++ b/src/4D_api.cpp @@ -231,13 +231,19 @@ similarly, but prefers the 2D resp. 3D interfaces if available. // with the input coordinate, then goes through again the list, and // use the first operation that does not require grids. i = 0; + NS_PROJ::io::DatabaseContextPtr dbContext; + try + { + if( P->ctx->cpp_context ) { + dbContext = P->ctx->cpp_context->getDatabaseContext().as_nullable(); + } + } + catch( const std::exception& ) {} for( const auto &alt: P->alternativeCoordinateOperations ) { auto coordOperation = dynamic_cast< NS_PROJ::operation::CoordinateOperation*>(alt.pj->iso_obj.get()); if( coordOperation ) { - if( coordOperation->gridsNeeded(P->ctx->cpp_context ? - P->ctx->cpp_context->databaseContext.as_nullable() : - nullptr).empty() ) { + if( coordOperation->gridsNeeded(dbContext).empty() ) { if( P->iCurCoordOp != i ) { std::string msg("Using coordinate operation "); msg += alt.name; -- cgit v1.2.3