26 #define FINDERFUNC set_proj_share
27 #define PERMANENT "PERMANENT"
30 static void alloc_options(
char *);
67 char buffa[300], factbuff[50];
69 char proj_in[250], *datum, *params;
90 if (strlen(factbuff) > 0)
91 sscanf(factbuff,
"%lf", &(info->
meters));
95 snprintf(proj_in,
sizeof(proj_in),
"%s", str);
99 snprintf(info->
proj,
sizeof(info->
proj),
"%s", str);
101 if (strlen(info->
proj) <= 0)
102 snprintf(info->
proj,
sizeof(info->
proj),
"ll");
109 for (i = 0; i < in_proj_keys->
nitems; i++) {
111 if (strcmp(in_proj_keys->
key[i],
"name") == 0) {
116 else if (strcmp(in_proj_keys->
key[i],
"init") == 0) {
121 else if (strcmp(in_proj_keys->
key[i],
"zone") == 0) {
127 else if (strcmp(in_proj_keys->
key[i],
"datum") == 0 ||
128 strcmp(in_proj_keys->
key[i],
"dx") == 0 ||
129 strcmp(in_proj_keys->
key[i],
"dy") == 0 ||
130 strcmp(in_proj_keys->
key[i],
"dz") == 0 ||
131 strcmp(in_proj_keys->
key[i],
"datumparams") == 0 ||
132 strcmp(in_proj_keys->
key[i],
"nadgrids") == 0 ||
133 strcmp(in_proj_keys->
key[i],
"towgs84") == 0 ||
134 strcmp(in_proj_keys->
key[i],
"ellps") == 0 ||
135 strcmp(in_proj_keys->
key[i],
"a") == 0 ||
136 strcmp(in_proj_keys->
key[i],
"b") == 0 ||
137 strcmp(in_proj_keys->
key[i],
"es") == 0 ||
138 strcmp(in_proj_keys->
key[i],
"f") == 0 ||
139 strcmp(in_proj_keys->
key[i],
"rf") == 0) {
144 else if (strcmp(in_proj_keys->
key[i],
"proj") == 0) {
145 if (strcmp(in_proj_keys->
value[i],
"ll") == 0)
146 snprintf(buffa,
sizeof(buffa),
"proj=longlat");
148 snprintf(buffa,
sizeof(buffa),
"proj=%s",
149 in_proj_keys->
value[i]);
155 else if (strcmp(in_proj_keys->
value[i],
"defined") == 0)
156 snprintf(buffa,
sizeof(buffa),
"%s", in_proj_keys->
key[i]);
159 snprintf(buffa,
sizeof(buffa),
"%s=%s", in_proj_keys->
key[i],
160 in_proj_keys->
value[i]);
162 alloc_options(buffa);
167 if (sscanf(str,
"%d", &(info->
zone)) != 1) {
170 if (info->
zone < 0) {
176 snprintf(buffa,
sizeof(buffa),
"south");
177 alloc_options(buffa);
180 snprintf(buffa,
sizeof(buffa),
"zone=%d", info->
zone);
181 alloc_options(buffa);
189 snprintf(buffa,
sizeof(buffa),
"ellps=%s", str);
190 alloc_options(buffa);
193 snprintf(buffa,
sizeof(buffa),
"a=%.16g", a);
194 alloc_options(buffa);
198 snprintf(buffa,
sizeof(buffa),
"b=%.16g", a);
200 snprintf(buffa,
sizeof(buffa),
"rf=%.16g", rf);
201 alloc_options(buffa);
206 snprintf(buffa,
sizeof(buffa),
"no_defs");
207 alloc_options(buffa);
212 snprintf(buffa,
sizeof(buffa),
"%s", params);
213 alloc_options(buffa);
219 else if (datum !=
NULL) {
222 snprintf(buffa,
sizeof(buffa),
"%s", params);
223 alloc_options(buffa);
231 snprintf(buffa,
sizeof(buffa),
"datum=%s", datum);
232 alloc_options(buffa);
243 #if PROJ_VERSION_MAJOR >= 6
247 alloc_options(
"type=crs");
249 pjc = proj_context_create();
250 if (!(pj = proj_create_argv(pjc, nopt, opt_in))) {
255 if (!(pj = pj_init(nopt, opt_in))) {
259 _(
"Unable to initialise PROJ with the following parameter list:"));
260 for (i = 0; i < nopt; i++) {
263 snprintf(
err,
sizeof(
err),
" +%s", opt_in[i]);
268 G_warning(
_(
"The PROJ error message: %s"), pj_strerrno(pj_errno));
274 int perr = proj_errno(pj);
279 #if PROJ_VERSION_MAJOR >= 6
280 if (proj_get_type(pj) == PJ_TYPE_BOUND_CRS) {
281 PJ *source_crs = proj_get_source_crs(pjc, pj);
293 for (i = 0; i < nopt; i++)
294 deflen += strlen(opt_in[i]) + 2;
298 snprintf(buffa,
sizeof(buffa),
"+%s ", opt_in[0]);
302 for (i = 1; i < nopt; i++) {
303 snprintf(buffa,
sizeof(buffa),
"+%s ", opt_in[i]);
304 strcat(info->
def, buffa);
311 static void alloc_options(
char *buffa)
315 nsize = strlen(buffa) + 1;
316 opt_in[nopt++] = (
char *)
G_malloc(nsize);
317 snprintf(opt_in[nopt - 1], nsize,
"%s", buffa);
344 char zonebuff[50], buffa[300];
355 info->
proj[0] =
'\0';
363 if ((str ==
NULL) || (str[0] ==
'\0')) {
367 snprintf(info->
proj,
sizeof(info->
proj),
"ll");
368 snprintf(buffa,
sizeof(buffa),
"proj=latlong ellps=WGS84");
369 alloc_options(buffa);
377 while (s = strtok(s,
" \t\n"), s) {
378 if (strncmp(s,
"+unfact=", 8) == 0) {
383 if (strncmp(s,
"+", 1) == 0)
385 if (nsize = strlen(s), nsize) {
387 fprintf(stderr,
"nopt = %d, s=%s\n", nopt, str);
389 _(
"Option input overflowed option table"));
392 if (strncmp(
"zone=", s, 5) == 0) {
393 snprintf(zonebuff,
sizeof(zonebuff),
"%s", s + 5);
394 sscanf(zonebuff,
"%d", &(info->
zone));
397 if (strncmp(s,
"init=", 5) == 0) {
401 if (strncmp(
"proj=", s, 5) == 0) {
402 snprintf(info->
proj,
sizeof(info->
proj),
"%s", s + 5);
403 if (strcmp(info->
proj,
"ll") == 0)
404 snprintf(buffa,
sizeof(buffa),
"proj=latlong");
406 snprintf(buffa,
sizeof(buffa),
"%s", s);
409 snprintf(buffa,
sizeof(buffa),
"%s", s);
411 alloc_options(buffa);
419 #if PROJ_VERSION_MAJOR >= 6
423 alloc_options(
"type=crs");
425 pjc = proj_context_create();
426 if (!(pj = proj_create_argv(pjc, nopt, opt_in))) {
427 G_warning(
_(
"Unable to initialize pj cause: %s"),
428 proj_errno_string(proj_context_errno(pjc)));
432 #if PROJ_VERSION_MAJOR >= 6
433 if (proj_get_type(pj) == PJ_TYPE_BOUND_CRS) {
434 PJ *source_crs = proj_get_source_crs(pjc, pj);
445 if (!(pj = pj_init(nopt, opt_in))) {
446 G_warning(
_(
"Unable to initialize pj cause: %s"),
447 pj_strerrno(pj_errno));
454 for (i = 0; i < nopt; i++)
455 deflen += strlen(opt_in[i]) + 2;
459 snprintf(buffa,
sizeof(buffa),
"+%s ", opt_in[0]);
463 for (i = 1; i < nopt; i++) {
464 snprintf(buffa,
sizeof(buffa),
"+%s ", opt_in[i]);
465 strcat(info->
def, buffa);
501 snprintf(pjnew->
proj,
sizeof(pjnew->
proj),
"ll");
502 if ((pjnew->
pj = pj_latlong_from_proj(pjold->
pj)) ==
NULL)
505 deftmp = pj_get_def(pjnew->
pj, 1);
521 static char *buf =
NULL;
522 const char *projshare;
523 static size_t buf_len = 0;
526 projshare = getenv(
"GRASS_PROJSHARE");
530 len = strlen(projshare) + strlen(
name) + 2;
539 snprintf(buf, buf_len,
"%s/%s", projshare,
name);
563 fprintf(stderr,
"%s: %s\n",
_(
"Input Projection Parameters"), str);
564 fprintf(stderr,
"%s: %.16g\n",
_(
"Input Unit Factor"),
574 fprintf(stderr,
"%s: %s\n",
_(
"Output Projection Parameters"), str);
575 fprintf(stderr,
"%s: %.16g\n",
_(
"Output Unit Factor"),
void G_free(void *)
Free allocated memory.
void void void void G_fatal_error(const char *,...) __attribute__((format(printf
void G_warning(const char *,...) __attribute__((format(printf
const char * G_find_key_value(const char *, const struct Key_Value *)
Find given key (case sensitive)
char * G_store(const char *)
Copy string to allocated memory.
int GPJ_get_default_datum_params_by_name(const char *, char **)
"Last resort" function to retrieve a "default" set of datum parameters for a datum (N....
int GPJ__get_datum_params(const struct Key_Value *, char **, char **)
Extract the datum transformation-related parameters from a set of general PROJ_INFO parameters.
int GPJ__get_ellipsoid_params(const struct Key_Value *, double *, double *, double *)
Get the ellipsoid parameters from proj keys structure.
int GPJ_get_equivalent_latlong(struct pj_info *, struct pj_info *)
int pj_get_kv(struct pj_info *info, const struct Key_Value *in_proj_keys, const struct Key_Value *in_units_keys)
Create a pj_info struct Co-ordinate System definition from a set of PROJ_INFO / PROJ_UNITS-style key-...
int pj_print_proj_params(const struct pj_info *iproj, const struct pj_info *oproj)
Print projection parameters as used by PROJ.4 for input and output co-ordinate systems.
const char * set_proj_share(const char *name)
int pj_get_string(struct pj_info *info, char *str)
Create a pj_info struct Co-ordinate System definition from a string with a sequence of key=value pair...
SYMBOL * err(FILE *fp, SYMBOL *s, char *msg)