Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Patch to fix issue with DatabaseContext #130

Merged
merged 1 commit into from
Jan 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 102 additions & 0 deletions recipe/0002-add-proj-networking-state-cache-inf.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
From 225df1ee596db14220796e89f8a5f6fc3ae1808f Mon Sep 17 00:00:00 2001
From: Even Rouault <even.rouault@spatialys.com>
Date: Mon, 5 Dec 2022 23:47:43 +0100
Subject: [PATCH] DatabaseContext::lookForGridInfo(): add PROJ networking
state in cache information (fixes pyproj4/pyproj#1192)

---
src/iso19111/factory.cpp | 17 ++++++++------
test/unit/test_network.cpp | 47 ++++++++++++++++++++++++++++++++++++++
2 files changed, 57 insertions(+), 7 deletions(-)

diff --git a/src/iso19111/factory.cpp b/src/iso19111/factory.cpp
index 96327a63f8..5bd686a9fd 100644
--- a/src/iso19111/factory.cpp
+++ b/src/iso19111/factory.cpp
@@ -3243,8 +3243,16 @@ bool DatabaseContext::lookForGridInfo(
std::string &fullFilename, std::string &packageName, std::string &url,
bool &directDownload, bool &openLicense, bool &gridAvailable) const {
Private::GridInfoCache info;
- const std::string key(projFilename +
- (considerKnownGridsAsAvailable ? "true" : "false"));
+
+ auto ctxt = d->pjCtxt();
+ if (ctxt == nullptr) {
+ ctxt = pj_get_default_ctx();
+ d->setPjCtxt(ctxt);
+ }
+
+ std::string key(projFilename);
+ key += proj_context_is_network_enabled(ctxt) ? "true" : "false";
+ key += considerKnownGridsAsAvailable ? "true" : "false";
if (d->getGridInfoFromCache(key, info)) {
fullFilename = info.fullFilename;
packageName = info.packageName;
@@ -3262,11 +3270,6 @@ bool DatabaseContext::lookForGridInfo(
directDownload = false;

fullFilename.resize(2048);
- auto ctxt = d->pjCtxt();
- if (ctxt == nullptr) {
- ctxt = pj_get_default_ctx();
- d->setPjCtxt(ctxt);
- }
int errno_before = proj_context_errno(ctxt);
gridAvailable = NS_PROJ::FileManager::open_resource_file(
ctxt, projFilename.c_str(), &fullFilename[0],
diff --git a/test/unit/test_network.cpp b/test/unit/test_network.cpp
index f16d04324b..0b258ed384 100644
--- a/test/unit/test_network.cpp
+++ b/test/unit/test_network.cpp
@@ -1974,4 +1974,51 @@ TEST(networking, proj_coordoperation_get_grid_used) {

#endif

+// ---------------------------------------------------------------------------
+
+#ifdef CURL_ENABLED
+
+TEST(networking, pyproj_issue_1192) {
+ if (!networkAccessOK) {
+ return;
+ }
+
+ const auto doTest = [](PJ_CONTEXT *ctxt) {
+ auto factory_context =
+ proj_create_operation_factory_context(ctxt, nullptr);
+ proj_operation_factory_context_set_grid_availability_use(
+ ctxt, factory_context, PROJ_GRID_AVAILABILITY_IGNORED);
+ proj_operation_factory_context_set_spatial_criterion(
+ ctxt, factory_context, PROJ_SPATIAL_CRITERION_PARTIAL_INTERSECTION);
+ auto from = proj_create(ctxt, "EPSG:4326");
+ auto to = proj_create(ctxt, "EPSG:2964");
+ auto pj_operations =
+ proj_create_operations(ctxt, from, to, factory_context);
+ proj_destroy(from);
+ proj_destroy(to);
+ auto num_operations = proj_list_get_count(pj_operations);
+ for (int i = 0; i < num_operations; ++i) {
+ PJ *P = proj_list_get(ctxt, pj_operations, i);
+ int is_instantiable = proj_coordoperation_is_instantiable(ctxt, P);
+ if (is_instantiable) {
+ EXPECT_TRUE(proj_pj_info(P).id != nullptr);
+ }
+ proj_destroy(P);
+ }
+ proj_operation_factory_context_destroy(factory_context);
+ proj_list_destroy(pj_operations);
+ };
+
+ auto ctx = proj_context_create();
+ proj_grid_cache_set_enable(ctx, false);
+ proj_context_set_enable_network(ctx, true);
+ doTest(ctx);
+ proj_context_set_enable_network(ctx, false);
+ doTest(ctx);
+
+ proj_context_destroy(ctx);
+}
+
+#endif
+
} // namespace
3 changes: 2 additions & 1 deletion recipe/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ source:
sha256: 003cd4010e52bb5eb8f7de1c143753aa830c8902b6ed01209f294846e40e6d39
patches:
- 0001-disable-geodsigntest.patch
- 0002-add-proj-networking-state-cache-inf.patch

build:
number: 1
number: 2
run_exports:
# so name changes in bugfix revisions. Pin to bugfix revision.
# https://abi-laboratory.pro/tracker/timeline/proj/
Expand Down