27 #define FINDERFUNC set_proj_share 28 #define PERMANENT "PERMANENT" 31 static void alloc_options(
char *);
68 char buffa[300], factbuff[50];
70 char proj_in[250], *datum, *params;
89 strcpy(factbuff, str);
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) {
128 else if (strcmp(in_proj_keys->
key[i],
"datum") == 0
129 || strcmp(in_proj_keys->
key[i],
"dx") == 0
130 || strcmp(in_proj_keys->
key[i],
"dy") == 0
131 || strcmp(in_proj_keys->
key[i],
"dz") == 0
132 || strcmp(in_proj_keys->
key[i],
"datumparams") == 0
133 || strcmp(in_proj_keys->
key[i],
"nadgrids") == 0
134 || strcmp(in_proj_keys->
key[i],
"towgs84") == 0
135 || strcmp(in_proj_keys->
key[i],
"ellps") == 0
136 || strcmp(in_proj_keys->
key[i],
"a") == 0
137 || strcmp(in_proj_keys->
key[i],
"b") == 0
138 || strcmp(in_proj_keys->
key[i],
"es") == 0
139 || strcmp(in_proj_keys->
key[i],
"f") == 0
140 || strcmp(in_proj_keys->
key[i],
"rf") == 0) {
146 else if (strcmp(in_proj_keys->
key[i],
"proj") == 0) {
147 if (strcmp(in_proj_keys->
value[i],
"ll") == 0)
148 sprintf(buffa,
"proj=longlat");
150 sprintf(buffa,
"proj=%s", in_proj_keys->
value[i]);
156 else if (strcmp(in_proj_keys->
value[i],
"defined") == 0)
157 sprintf(buffa,
"%s", in_proj_keys->
key[i]);
160 sprintf(buffa,
"%s=%s",
161 in_proj_keys->
key[i], in_proj_keys->
value[i]);
163 alloc_options(buffa);
168 if (sscanf(str,
"%d", &(info->
zone)) != 1) {
171 if (info->
zone < 0) {
177 sprintf(buffa,
"south");
178 alloc_options(buffa);
181 sprintf(buffa,
"zone=%d", info->
zone);
182 alloc_options(buffa);
190 sprintf(buffa,
"ellps=%s", str);
191 alloc_options(buffa);
194 sprintf(buffa,
"a=%.16g", a);
195 alloc_options(buffa);
199 sprintf(buffa,
"b=%.16g", a);
201 sprintf(buffa,
"rf=%.16g", rf);
202 alloc_options(buffa);
208 sprintf(buffa,
"no_defs");
209 alloc_options(buffa);
214 sprintf(buffa,
"%s", params);
215 alloc_options(buffa);
221 else if (datum !=
NULL) {
224 sprintf(buffa,
"%s", params);
225 alloc_options(buffa);
233 sprintf(buffa,
"datum=%s", datum);
234 alloc_options(buffa);
245 #if PROJ_VERSION_MAJOR >= 6 249 alloc_options(
"type=crs");
251 pjc = proj_context_create();
252 if (!(pj = proj_create_argv(pjc, nopt, opt_in))) {
257 if (!(pj = pj_init(nopt, opt_in))) {
260 _(
"Unable to initialise PROJ with the following parameter list:"));
261 for (i = 0; i < nopt; i++) {
264 sprintf(err,
" +%s", opt_in[i]);
269 G_warning(
_(
"The PROJ error message: %s"), pj_strerrno(pj_errno));
275 int perr = proj_errno(pj);
284 for (i = 0; i < nopt; i++)
285 deflen += strlen(opt_in[i]) + 2;
289 sprintf(buffa,
"+%s ", opt_in[0]);
290 strcpy(info->
def, buffa);
293 for (i = 1; i < nopt; i++) {
294 sprintf(buffa,
"+%s ", opt_in[i]);
295 strcat(info->
def, buffa);
302 static void alloc_options(
char *buffa)
306 nsize = strlen(buffa);
307 opt_in[nopt++] = (
char *)
G_malloc(nsize + 1);
308 sprintf(opt_in[nopt - 1],
"%s", buffa);
335 char zonebuff[50], buffa[300];
345 info->
proj[0] =
'\0';
353 if ((str ==
NULL) || (str[0] ==
'\0')) {
357 sprintf(info->
proj,
"ll");
358 sprintf(buffa,
"proj=latlong ellps=WGS84");
359 alloc_options(buffa);
367 while (s = strtok(s,
" \t\n"), s) {
368 if (strncmp(s,
"+unfact=", 8) == 0) {
373 if (strncmp(s,
"+", 1) == 0)
375 if (nsize = strlen(s), nsize) {
377 fprintf(stderr,
"nopt = %d, s=%s\n", nopt, str);
381 if (strncmp(
"zone=", s, 5) == 0) {
382 sprintf(zonebuff,
"%s", s + 5);
383 sscanf(zonebuff,
"%d", &(info->
zone));
386 if (strncmp(s,
"init=", 5) == 0) {
390 if (strncmp(
"proj=", s, 5) == 0) {
391 sprintf(info->
proj,
"%s", s + 5);
392 if (strcmp(info->
proj,
"ll") == 0)
393 sprintf(buffa,
"proj=latlong");
395 sprintf(buffa,
"%s", s);
398 sprintf(buffa,
"%s", s);
400 alloc_options(buffa);
408 #if PROJ_VERSION_MAJOR >= 6 412 alloc_options(
"type=crs");
414 pjc = proj_context_create();
415 if (!(pj = proj_create_argv(pjc, nopt, opt_in))) {
416 G_warning(
_(
"Unable to initialize pj cause: %s"),
417 proj_errno_string(proj_context_errno(pjc)));
424 if (!(pj = pj_init(nopt, opt_in))) {
425 G_warning(
_(
"Unable to initialize pj cause: %s"),
426 pj_strerrno(pj_errno));
433 for (i = 0; i < nopt; i++)
434 deflen += strlen(opt_in[i]) + 2;
438 sprintf(buffa,
"+%s ", opt_in[0]);
439 strcpy(info->
def, buffa);
442 for (i = 1; i < nopt; i++) {
443 sprintf(buffa,
"+%s ", opt_in[i]);
444 strcat(info->
def, buffa);
478 sprintf(pjnew->
proj,
"ll");
479 if ((pjnew->
pj = pj_latlong_from_proj(pjold->
pj)) ==
NULL)
482 deftmp = pj_get_def(pjnew->
pj, 1);
498 static char *buf =
NULL;
499 const char *projshare;
500 static size_t buf_len = 0;
503 projshare =
getenv(
"GRASS_PROJSHARE");
507 len = strlen(projshare) + strlen(name) + 2;
516 sprintf(buf,
"%s/%s", projshare, name);
539 fprintf(stderr,
"%s: %s\n",
_(
"Input Projection Parameters"),
541 fprintf(stderr,
"%s: %.16g\n",
_(
"Input Unit Factor"),
551 fprintf(stderr,
"%s: %s\n",
_(
"Output Projection Parameters"),
553 fprintf(stderr,
"%s: %.16g\n",
_(
"Output Unit Factor"),
const char * set_proj_share(const char *name)
void void void void G_fatal_error(const char *,...) __attribute__((format(printf
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.
int GPJ_get_equivalent_latlong(struct pj_info *, struct pj_info *)
void G_free(void *)
Free allocated memory.
int GPJ__get_ellipsoid_params(const struct Key_Value *, double *, double *, double *)
Get the ellipsoid parameters from proj keys structure.
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...
SYMBOL * err(FILE *fp, SYMBOL *s, char *msg)
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 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-...
void G_warning(const char *,...) __attribute__((format(printf
char * G_store(const char *)
Copy string to allocated memory.
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...
const char * G_find_key_value(const char *, const struct Key_Value *)
Find given key (case sensitive)