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 sprintf(proj_in,
"%s", str);
99 sprintf(info->
proj,
"%s", str);
101 if (strlen(info->
proj) <= 0)
102 sprintf(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 sprintf(buffa,
"proj=longlat");
148 sprintf(buffa,
"proj=%s", in_proj_keys->
value[i]);
154 else if (strcmp(in_proj_keys->
value[i],
"defined") == 0)
155 sprintf(buffa,
"%s", in_proj_keys->
key[i]);
158 sprintf(buffa,
"%s=%s", in_proj_keys->
key[i],
159 in_proj_keys->
value[i]);
161 alloc_options(buffa);
166 if (sscanf(str,
"%d", &(info->
zone)) != 1) {
169 if (info->
zone < 0) {
175 sprintf(buffa,
"south");
176 alloc_options(buffa);
179 sprintf(buffa,
"zone=%d", info->
zone);
180 alloc_options(buffa);
188 sprintf(buffa,
"ellps=%s", str);
189 alloc_options(buffa);
192 sprintf(buffa,
"a=%.16g", a);
193 alloc_options(buffa);
197 sprintf(buffa,
"b=%.16g", a);
199 sprintf(buffa,
"rf=%.16g", rf);
200 alloc_options(buffa);
205 sprintf(buffa,
"no_defs");
206 alloc_options(buffa);
211 sprintf(buffa,
"%s", params);
212 alloc_options(buffa);
218 else if (datum !=
NULL) {
221 sprintf(buffa,
"%s", params);
222 alloc_options(buffa);
230 sprintf(buffa,
"datum=%s", datum);
231 alloc_options(buffa);
242 #if PROJ_VERSION_MAJOR >= 6
246 alloc_options(
"type=crs");
248 pjc = proj_context_create();
249 if (!(pj = proj_create_argv(pjc, nopt, opt_in))) {
254 if (!(pj = pj_init(nopt, opt_in))) {
258 _(
"Unable to initialise PROJ with the following parameter list:"));
259 for (i = 0; i < nopt; i++) {
262 sprintf(
err,
" +%s", opt_in[i]);
267 G_warning(
_(
"The PROJ error message: %s"), pj_strerrno(pj_errno));
273 int perr = proj_errno(pj);
278 #if PROJ_VERSION_MAJOR >= 6
279 if (proj_get_type(pj) == PJ_TYPE_BOUND_CRS) {
280 PJ *source_crs = proj_get_source_crs(pjc, pj);
292 for (i = 0; i < nopt; i++)
293 deflen += strlen(opt_in[i]) + 2;
297 sprintf(buffa,
"+%s ", opt_in[0]);
301 for (i = 1; i < nopt; i++) {
302 sprintf(buffa,
"+%s ", opt_in[i]);
303 strcat(info->
def, buffa);
310 static void alloc_options(
char *buffa)
314 nsize = strlen(buffa);
315 opt_in[nopt++] = (
char *)
G_malloc(nsize + 1);
316 sprintf(opt_in[nopt - 1],
"%s", buffa);
343 char zonebuff[50], buffa[300];
354 info->
proj[0] =
'\0';
362 if ((str ==
NULL) || (str[0] ==
'\0')) {
366 sprintf(info->
proj,
"ll");
367 sprintf(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 sprintf(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 sprintf(info->
proj,
"%s", s + 5);
402 if (strcmp(info->
proj,
"ll") == 0)
403 sprintf(buffa,
"proj=latlong");
405 sprintf(buffa,
"%s", s);
408 sprintf(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 sprintf(buffa,
"+%s ", opt_in[0]);
462 for (i = 1; i < nopt; i++) {
463 sprintf(buffa,
"+%s ", opt_in[i]);
464 strcat(info->
def, buffa);
500 sprintf(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 sprintf(buf,
"%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)