aboutsummaryrefslogtreecommitdiff
path: root/src/transformations
diff options
context:
space:
mode:
authorPROJ-BOT <59655370+PROJ-BOT@users.noreply.github.com>2020-04-05 12:52:29 +0200
committerGitHub <noreply@github.com>2020-04-05 12:52:29 +0200
commit7018f85e2d53820c31cf3c633f7020f6630580b9 (patch)
tree85d33a006570b5dad6804e768512d9e7931156ed /src/transformations
parentd43a473758fcc44f4539edd082d988a0c01cd56b (diff)
downloadPROJ-7018f85e2d53820c31cf3c633f7020f6630580b9.tar.gz
PROJ-7018f85e2d53820c31cf3c633f7020f6630580b9.zip
[Backport 7.0] hgridshift/vgridshift: defer grid opening when grid has already been opened (#2132)
Diffstat (limited to 'src/transformations')
-rw-r--r--src/transformations/hgridshift.cpp51
-rw-r--r--src/transformations/vgridshift.cpp53
2 files changed, 91 insertions, 13 deletions
diff --git a/src/transformations/hgridshift.cpp b/src/transformations/hgridshift.cpp
index 122a7ab2..b28eaf48 100644
--- a/src/transformations/hgridshift.cpp
+++ b/src/transformations/hgridshift.cpp
@@ -12,6 +12,25 @@ PROJ_HEAD(hgridshift, "Horizontal grid shift");
using namespace NS_PROJ;
+#ifdef __MINGW32__
+// mingw32-win32 doesn't implement std::mutex
+namespace {
+class MyMutex {
+ public:
+ // cppcheck-suppress functionStatic
+ void lock() { pj_acquire_lock(); }
+ // cppcheck-suppress functionStatic
+ void unlock() { pj_release_lock(); }
+};
+}
+#else
+#include <mutex>
+#define MyMutex std::mutex
+#endif
+
+static MyMutex gMutex{};
+static std::set<std::string> gKnownGrids{};
+
namespace { // anonymous namespace
struct hgridshiftData {
double t_final = 0;
@@ -160,18 +179,36 @@ PJ *TRANSFORMATION(hgridshift,0) {
if (pj_param(P->ctx, P->params, "tt_epoch").i)
Q->t_epoch = pj_param (P->ctx, P->params, "dt_epoch").f;
-
if( P->ctx->defer_grid_opening ) {
Q->defer_grid_opening = true;
}
else {
- Q->grids = pj_hgrid_init(P, "grids");
- /* Was gridlist compiled properly? */
- if ( proj_errno(P) ) {
- proj_log_error(P, "hgridshift: could not find required grid(s).");
- return destructor(P, PJD_ERR_FAILED_TO_LOAD_GRID);
+ const char *gridnames = pj_param(P->ctx, P->params, "sgrids").s;
+ gMutex.lock();
+ const bool isKnownGrid = gKnownGrids.find(gridnames) != gKnownGrids.end();
+ gMutex.unlock();
+ if( isKnownGrid ) {
+ Q->defer_grid_opening = true;
}
- }
+ else {
+ Q->grids = pj_hgrid_init(P, "grids");
+ /* Was gridlist compiled properly? */
+ if ( proj_errno(P) ) {
+ proj_log_error(P, "hgridshift: could not find required grid(s).");
+ return destructor(P, PJD_ERR_FAILED_TO_LOAD_GRID);
+ }
+
+ gMutex.lock();
+ gKnownGrids.insert(gridnames);
+ gMutex.unlock();
+ }
+ }
return P;
}
+
+void pj_clear_hgridshift_knowngrids_cache() {
+ gMutex.lock();
+ gKnownGrids.clear();
+ gMutex.unlock();
+}
diff --git a/src/transformations/vgridshift.cpp b/src/transformations/vgridshift.cpp
index 121b795a..6ee8a6b0 100644
--- a/src/transformations/vgridshift.cpp
+++ b/src/transformations/vgridshift.cpp
@@ -12,6 +12,27 @@ PROJ_HEAD(vgridshift, "Vertical grid shift");
using namespace NS_PROJ;
+
+#ifdef __MINGW32__
+// mingw32-win32 doesn't implement std::mutex
+namespace {
+class MyMutex {
+ public:
+ // cppcheck-suppress functionStatic
+ void lock() { pj_acquire_lock(); }
+ // cppcheck-suppress functionStatic
+ void unlock() { pj_release_lock(); }
+};
+}
+#else
+#include <mutex>
+#define MyMutex std::mutex
+#endif
+
+static MyMutex gMutex{};
+static std::set<std::string> gKnownGrids{};
+
+
namespace { // anonymous namespace
struct vgridshiftData {
double t_final = 0;
@@ -192,13 +213,27 @@ PJ *TRANSFORMATION(vgridshift,0) {
Q->defer_grid_opening = true;
}
else {
- /* Build gridlist. P->vgridlist_geoid can be empty if +grids only ask for optional grids. */
- Q->grids = pj_vgrid_init(P, "grids");
+ const char *gridnames = pj_param(P->ctx, P->params, "sgrids").s;
+ gMutex.lock();
+ const bool isKnownGrid = gKnownGrids.find(gridnames) != gKnownGrids.end();
+ gMutex.unlock();
- /* Was gridlist compiled properly? */
- if ( proj_errno(P) ) {
- proj_log_error(P, "vgridshift: could not find required grid(s).");
- return destructor(P, PJD_ERR_FAILED_TO_LOAD_GRID);
+ if( isKnownGrid ) {
+ Q->defer_grid_opening = true;
+ }
+ else {
+ /* Build gridlist. P->vgridlist_geoid can be empty if +grids only ask for optional grids. */
+ Q->grids = pj_vgrid_init(P, "grids");
+
+ /* Was gridlist compiled properly? */
+ if ( proj_errno(P) ) {
+ proj_log_error(P, "vgridshift: could not find required grid(s).");
+ return destructor(P, PJD_ERR_FAILED_TO_LOAD_GRID);
+ }
+
+ gMutex.lock();
+ gKnownGrids.insert(gridnames);
+ gMutex.unlock();
}
}
@@ -214,3 +249,9 @@ PJ *TRANSFORMATION(vgridshift,0) {
return P;
}
+
+void pj_clear_vgridshift_knowngrids_cache() {
+ gMutex.lock();
+ gKnownGrids.clear();
+ gMutex.unlock();
+}