aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEven Rouault <even.rouault@spatialys.com>2021-03-10 20:44:42 +0100
committerGitHub <noreply@github.com>2021-03-10 20:44:42 +0100
commit554f95d705269bd726ca88f49f32eb09fcaa0037 (patch)
tree16c10ca80597a25133b7321d2277504e55fbb9bd /src
parente6b20d968aa358e9863dd5939976368054a51715 (diff)
parent1e47f2bda51fda1ab424c04da7d2c33a38c10e87 (diff)
downloadPROJ-554f95d705269bd726ca88f49f32eb09fcaa0037.tar.gz
PROJ-554f95d705269bd726ca88f49f32eb09fcaa0037.zip
Merge pull request #2570 from rouault/fix_proj_lp_dist_crs
Make proj_lp_dist() and proj_geod() work on a PJ* CRS object
Diffstat (limited to 'src')
-rw-r--r--src/iso19111/c_api.cpp21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/iso19111/c_api.cpp b/src/iso19111/c_api.cpp
index 0ea74394..8f1fac70 100644
--- a/src/iso19111/c_api.cpp
+++ b/src/iso19111/c_api.cpp
@@ -59,6 +59,7 @@
#include "proj_experimental.h"
// clang-format on
#include "proj_constants.h"
+#include "geodesic.h"
using namespace NS_PROJ::common;
using namespace NS_PROJ::crs;
@@ -205,6 +206,26 @@ static PJ *pj_obj_create(PJ_CONTEXT *ctx, const IdentifiedObjectNNPtr &objIn) {
pj->ctx = ctx;
pj->descr = "ISO-19111 object";
pj->iso_obj = objIn;
+ try {
+ auto crs = dynamic_cast<const CRS *>(objIn.get());
+ if (crs) {
+ auto geodCRS = crs->extractGeodeticCRS();
+ if (geodCRS) {
+ const auto &ellps = geodCRS->ellipsoid();
+ const double a = ellps->semiMajorAxis().getSIValue();
+ const double es = ellps->squaredEccentricity();
+ pj_calc_ellipsoid_params(pj, a, es);
+ assert(pj->geod == nullptr);
+ pj->geod = static_cast<struct geod_geodesic *>(
+ calloc(1, sizeof(struct geod_geodesic)));
+ if (pj->geod) {
+ geod_init(pj->geod, pj->a,
+ pj->es / (1 + sqrt(pj->one_es)));
+ }
+ }
+ }
+ } catch (const std::exception &) {
+ }
}
ctx->safeAutoCloseDbIfNeeded();
return pj;