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);
343 char zonebuff[50], buffa[300];
354 info->
proj[0] =
'\0';
362 if ((str ==
NULL) || (str[0] ==
'\0')) {
366 snprintf(info->
proj,
sizeof(info->
proj),
"ll");
367 snprintf(buffa,
sizeof(buffa),
"proj=latlong ellps=WGS84");
368 alloc_options(buffa);
376 while (s = strtok(s,
" \t\n"), s) {
377 if (strncmp(s,
"+unfact=", 8) == 0) {
382 if (strncmp(s,
"+", 1) == 0)
384 if (nsize = strlen(s), nsize) {
386 fprintf(stderr,
"nopt = %d, s=%s\n", nopt, str);
388 _(
"Option input overflowed option table"));
391 if (strncmp(
"zone=", s, 5) == 0) {
392 snprintf(zonebuff,
sizeof(zonebuff),
"%s", s + 5);
393 sscanf(zonebuff,
"%d", &(info->
zone));
396 if (strncmp(s,
"init=", 5) == 0) {
400 if (strncmp(
"proj=", s, 5) == 0) {
401 snprintf(info->
proj,
sizeof(info->
proj),
"%s", s + 5);
402 if (strcmp(info->
proj,
"ll") == 0)
403 snprintf(buffa,
sizeof(buffa),
"proj=latlong");
405 snprintf(buffa,
sizeof(buffa),
"%s", s);
408 snprintf(buffa,
sizeof(buffa),
"%s", s);
410 alloc_options(buffa);
418 #if PROJ_VERSION_MAJOR >= 6
422 alloc_options(
"type=crs");
424 pjc = proj_context_create();
425 if (!(pj = proj_create_argv(pjc, nopt, opt_in))) {
426 G_warning(
_(
"Unable to initialize pj cause: %s"),
427 proj_errno_string(proj_context_errno(pjc)));
431 #if PROJ_VERSION_MAJOR >= 6
432 if (proj_get_type(pj) == PJ_TYPE_BOUND_CRS) {
433 PJ *source_crs = proj_get_source_crs(pjc, pj);
444 if (!(pj = pj_init(nopt, opt_in))) {
445 G_warning(
_(
"Unable to initialize pj cause: %s"),
446 pj_strerrno(pj_errno));
453 for (i = 0; i < nopt; i++)
454 deflen += strlen(opt_in[i]) + 2;
458 snprintf(buffa,
sizeof(buffa),
"+%s ", opt_in[0]);
462 for (i = 1; i < nopt; i++) {
463 snprintf(buffa,
sizeof(buffa),
"+%s ", opt_in[i]);
464 strcat(info->
def, buffa);
500 snprintf(pjnew->
proj,
sizeof(pjnew->
proj),
"ll");
501 if ((pjnew->
pj = pj_latlong_from_proj(pjold->
pj)) ==
NULL)
504 deftmp = pj_get_def(pjnew->
pj, 1);
520 static char *buf =
NULL;
521 const char *projshare;
522 static size_t buf_len = 0;
525 projshare = getenv(
"GRASS_PROJSHARE");
529 len = strlen(projshare) + strlen(
name) + 2;
538 snprintf(buf, buf_len,
"%s/%s", projshare,
name);
562 fprintf(stderr,
"%s: %s\n",
_(
"Input Projection Parameters"), str);
563 fprintf(stderr,
"%s: %.16g\n",
_(
"Input Unit Factor"),
573 fprintf(stderr,
"%s: %s\n",
_(
"Output Projection Parameters"), str);
574 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)