Skip to content

Commit 4b644a4

Browse files
committed
use proj.db in same directory as binary to prevent breaking when proj is installed
1 parent f67d676 commit 4b644a4

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

.github/workflows/cmake-test-on.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ jobs:
128128
129129
# Bundle data files if they exist
130130
[ -f fuel.lut ] && cp fuel.lut dist/
131+
[ -f proj.db ] && cp proj.db dist/
131132
[ -f settings.ini ] && cp settings.ini dist/
132133
[ -f data/fuel.lut ] && cp data/fuel.lut dist/
133134
[ -f data/settings.ini ] && cp data/settings.ini dist/
@@ -156,6 +157,7 @@ jobs:
156157
157158
# Bundle data files if they exist
158159
if (Test-Path fuel.lut) { Copy-Item fuel.lut dist\ }
160+
if (Test-Path proj.db) { Copy-Item proj.db dist\ }
159161
if (Test-Path settings.ini) { Copy-Item settings.ini dist\ }
160162
if (Test-Path data\fuel.lut) { Copy-Item data\fuel.lut dist\ }
161163
if (Test-Path data\settings.ini) { Copy-Item data\settings.ini dist\ }

src/cpp/fs/UTM.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,23 @@
33
#include <proj.h>
44
#include "Log.h"
55
#include "Point.h"
6+
#include "Settings.h"
67
#include "unstable.h"
78
#include "Util.h"
89
namespace fs
910
{
11+
PJ_CONTEXT* get_context()
12+
{
13+
auto pjc = proj_context_create();
14+
string db_path = Settings::getRoot() + "proj.db";
15+
logging::debug("Trying to set db path to %s", db_path.c_str());
16+
if (!proj_context_set_database_path(pjc, db_path.c_str(), NULL, NULL))
17+
{
18+
logging::fatal("Can't set proj.db path");
19+
}
20+
logging::verbose("Succeeded trying to set db path to %s", db_path.c_str());
21+
return pjc;
22+
}
1023
class Point;
1124
PJ* normalized_context(PJ_CONTEXT* C, const string_view proj4_from, const string_view proj4_to)
1225
{
@@ -25,7 +38,7 @@ void from_lat_long(const string_view proj4, const fs::Point& point, MathSize* x,
2538
{
2639
// see https://proj.org/en/stable/development/quickstart.html
2740
// do this in a function so we can hide and clean up intial context
28-
PJ_CONTEXT* C = proj_context_create();
41+
PJ_CONTEXT* C = get_context();
2942
auto P = normalized_context(C, "EPSG:4326", proj4);
3043
// Given that we have used proj_normalize_for_visualization(), the order
3144
// of coordinates is longitude, latitude, and values are expressed in
@@ -56,7 +69,7 @@ fs::Point to_lat_long(const string_view proj4, const MathSize x, const MathSize
5669
{
5770
// see https://proj.org/en/stable/development/quickstart.html
5871
// do this in a function so we can hide and clean up intial context
59-
PJ_CONTEXT* C = proj_context_create();
72+
PJ_CONTEXT* C = get_context();
6073
auto P = normalized_context(C, proj4, "EPSG:4326");
6174
// Given that we have used proj_normalize_for_visualization(), the order
6275
// of coordinates is longitude, latitude, and values are expressed in

0 commit comments

Comments
 (0)