21 #include <grass/gis.h>
22 #include <grass/glocale.h>
23 #include <grass/gprojects.h>
43 while (list !=
NULL) {
48 dstruct->dx = list->
dx;
49 dstruct->dy = list->
dy;
50 dstruct->dz = list->
dz;
87 struct gpj_datum_transform_list *list, *old;
99 *params =
G_store(list->params);
101 while (list->next !=
NULL) {
175 char **datumname,
char **params)
193 G_asprintf(params,
"nadgrids=%s%s/%s", gisbase, GRIDDIR,
242 char buff[1024], answer[100];
245 struct gpj_datum_transform_list *list, *listhead, *old;
246 int transformcount, currenttransform;
250 if (
NULL == (Tmp_fd = fopen(Tmp_file,
"w"))) {
251 G_warning(_(
"Unable to open temporary file"));
254 fprintf(Tmp_fd,
"Number\tDetails\t\n---\n");
258 while (list !=
NULL) {
263 "%d\tUsed in %s\n\t(PROJ.4 Params %s)\n\t%s\n---\n",
264 list->count, list->where_used, list->params,
274 (
"\nNow select Datum Transformation Parameters\n"));
276 (
"Please think carefully about the area covered by your data\n"
277 "and the accuracy you require before making your selection.\n"));
279 (
"\nEnter 'list' to see the list of available Parameter sets\n"));
281 (
"Enter the corresponding number, or <RETURN> to cancel request\n"));
282 fprintf(stderr,
">");
283 }
while (!
G_gets(answer));
285 if (strlen(answer) == 0) {
290 if (strcmp(answer,
"list") == 0) {
293 pager =
getenv(
"GRASS_PAGER");
294 if (!pager || strlen(pager) == 0)
298 sprintf(buff,
"%s \"%s\" 1>&2", pager,
303 if ((sscanf(answer,
"%d", ¤ttransform) != 1) ||
304 currenttransform > transformcount ||
305 currenttransform < 1) {
309 fprintf(stderr, (
"\ninvalid transformation number\n"));
320 while (list !=
NULL) {
323 if (list->count == currenttransform)
338 (
"\nPlease specify datum transformation parameters in PROJ.4 syntax. Examples:\n"));
340 (
"\ttowgs84=dx,dy,dz\t(3-parameter transformation)\n"));
342 (
"\ttowgs84=dx,dy,dz,rx,ry,rz,m\t(7-parameter transformation)\n"));
344 (
"\tnadgrids=alaska\t(Tables-based grid-shifting transformation)\n"));
345 fprintf(stderr, _(
"Hit RETURN to cancel request\n"));
346 fprintf(stderr,
">");
347 }
while (!
G_gets(answer));
349 if (strlen(answer) == 0)
353 "Parameters to be used are:\n\"%s\"\nIs this correct?",
382 char file[GPATH_MAX];
385 struct gpj_datum_transform_list *current =
NULL, *outputlist =
NULL;
386 struct gpj_datum dstruct;
390 if (dstruct.dx < 99999 && dstruct.dy < 99999 && dstruct.dz < 99999) {
395 current = outputlist =
396 G_malloc(
sizeof(
struct gpj_datum_transform_list));
398 current = current->next =
399 G_malloc(
sizeof(
struct gpj_datum_transform_list));
400 G_asprintf(&(current->params),
"towgs84=%.3f,%.3f,%.3f", dstruct.dx,
401 dstruct.dy, dstruct.dz);
402 G_asprintf(&(current->where_used),
"whole %s region", inputname);
404 "Default 3-Parameter Transformation (May not be optimum for "
405 "older datums; use this only if no more appropriate options "
408 current->count = count;
409 current->next =
NULL;
415 sprintf(file,
"%s%s",
G_gisbase(), DATUMTRANSFORMTABLE);
417 fd = fopen(file,
"r");
419 G_warning(_(
"Unable to open datum table file <%s>"), file);
423 for (line = 1;
G_getl2(buf,
sizeof(buf), fd); line++) {
424 char name[100], params[1024], where_used[1024], comment[1024];
427 if (*buf ==
'\0' || *buf ==
'#')
430 if (sscanf(buf,
"%99s \"%1023[^\"]\" \"%1023[^\"]\" \"%1023[^\"]\"",
431 name, params, where_used, comment) != 4) {
432 G_warning(_(
"Error in datum table file <%s>, line %d"), file,
441 current = outputlist =
442 G_malloc(
sizeof(
struct gpj_datum_transform_list));
444 current = current->next =
445 G_malloc(
sizeof(
struct gpj_datum_transform_list));
446 current->params =
G_store(params);
447 current->where_used =
G_store(where_used);
448 current->comment =
G_store(comment);
450 current->count = count;
451 current->next =
NULL;
474 char file[GPATH_MAX];
482 fd = fopen(file,
"r");
484 G_warning(_(
"Unable to open datum table file <%s>"), file);
488 for (line = 1;
G_getl2(buf,
sizeof(buf), fd); line++) {
493 if (*buf ==
'\0' || *buf ==
'#')
496 if (sscanf(buf,
"%s \"%1023[^\"]\" %s dx=%lf dy=%lf dz=%lf",
497 name, descr, ellps, &dx, &dy, &dz) != 6) {
498 G_warning(_(
"Error in datum table file <%s>, line %d"), file,
504 current = outputlist = G_malloc(
sizeof(
struct datum_list));
532 G_free(dstruct->longname);
547 while (dstruct !=
NULL) {