MCPcopy Create free account
hub / github.com/OSGeo/PROJ / cs2cs_emulation_setup

Function cs2cs_emulation_setup

src/create.cpp:49–203  ·  view source on GitHub ↗

/

Source from the content-addressed store, hash-verified

47
48/*************************************************************************************/
49static int cs2cs_emulation_setup(PJ *P) {
50 /**************************************************************************************
51 If any cs2cs style modifiers are given (axis=..., towgs84=..., ) create the
52 4D API equivalent operations, so the preparation and finalization steps in
53 the pj_inv/pj_fwd invocators can emulate the behavior of pj_transform and
54 the cs2cs app.
55
56 Returns 1 on success, 0 on failure
57 **************************************************************************************/
58 PJ *Q;
59 paralist *p;
60 int do_cart = 0;
61 if (nullptr == P)
62 return 0;
63
64 /* Don't recurse when calling proj_create (which calls us back) */
65 if (pj_param_exists(P->params, "break_cs2cs_recursion"))
66 return 1;
67
68 /* Swap axes? */
69 p = pj_param_exists(P->params, "axis");
70
71 const bool disable_grid_presence_check =
72 pj_param_exists(P->params, "disable_grid_presence_check") != nullptr;
73
74 /* Don't axisswap if data are already in "enu" order */
75 if (p && (0 != strcmp("enu", p->param))) {
76 size_t def_size = 100 + strlen(P->axis);
77 char *def = static_cast<char *>(malloc(def_size));
78 if (nullptr == def)
79 return 0;
80 snprintf(def, def_size,
81 "break_cs2cs_recursion proj=axisswap axis=%s", P->axis);
82 Q = pj_create_internal(P->ctx, def);
83 free(def);
84 if (nullptr == Q)
85 return 0;
86 P->axisswap = skip_prep_fin(Q);
87 }
88
89 /* Geoid grid(s) given? */
90 p = pj_param_exists(P->params, "geoidgrids");
91 if (!disable_grid_presence_check && p &&
92 strlen(p->param) > strlen("geoidgrids=")) {
93 char *gridnames = p->param + strlen("geoidgrids=");
94 size_t def_size = 100 + 2 * strlen(gridnames);
95 char *def = static_cast<char *>(malloc(def_size));
96 if (nullptr == def)
97 return 0;
98 snprintf(def, def_size,
99 "break_cs2cs_recursion proj=vgridshift grids=%s",
100 pj_double_quote_string_param_if_needed(gridnames).c_str());
101 Q = pj_create_internal(P->ctx, def);
102 free(def);
103 if (nullptr == Q)
104 return 0;
105 P->vgridshift = skip_prep_fin(Q);
106 }

Callers 1

pj_create_argv_internalFunction · 0.85

Calls 5

pj_param_existsFunction · 0.85
pj_create_internalFunction · 0.85
skip_prep_finFunction · 0.85
pj_inherit_ellipsoid_defFunction · 0.85

Tested by

no test coverage detected