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 !=
NULL) {
174 char **datumname,
char **params)
192 G_asprintf(params,
"nadgrids=%s%s/%s", gisbase, GRIDDIR,
241 char buff[1024], answer[100];
244 struct gpj_datum_transform_list *list, *listhead, *
old;
245 int transformcount, currenttransform;
249 if (
NULL == (Tmp_fd = fopen(Tmp_file,
"w"))) {
250 G_warning(_(
"Unable to open temporary file"));
253 fprintf(Tmp_fd,
"Number\tDetails\t\n---\n");
257 while (list !=
NULL) {
262 "%d\tUsed in %s\n\t(PROJ.4 Params %s)\n\t%s\n---\n",
263 list->count, list->where_used, list->params,
273 (
"\nNow select Datum Transformation Parameters\n"));
275 (
"Please think carefully about the area covered by your data\n"
276 "and the accuracy you require before making your selection.\n"));
278 (
"\nEnter 'list' to see the list of available Parameter sets\n"));
280 (
"Enter the corresponding number, or <RETURN> to cancel request\n"));
281 fprintf(stderr,
">");
282 }
while (!
G_gets(answer));
284 if (strlen(answer) == 0) {
289 if (strcmp(answer,
"list") == 0) {
292 pager =
getenv(
"GRASS_PAGER");
293 if (!pager || strlen(pager) == 0)
297 sprintf(buff,
"%s \"%s\" 1>&2", pager,
302 if ((sscanf(answer,
"%d", ¤ttransform) != 1) ||
303 currenttransform > transformcount ||
304 currenttransform < 1) {
308 fprintf(stderr, (
"\ninvalid transformation number\n"));
319 while (list !=
NULL) {
322 if (list->count == currenttransform)
337 (
"\nPlease specify datum transformation parameters in PROJ.4 syntax. Examples:\n"));
339 (
"\ttowgs84=dx,dy,dz\t(3-parameter transformation)\n"));
341 (
"\ttowgs84=dx,dy,dz,rx,ry,rz,m\t(7-parameter transformation)\n"));
343 (
"\tnadgrids=alaska\t(Tables-based grid-shifting transformation)\n"));
344 fprintf(stderr, _(
"Hit RETURN to cancel request\n"));
345 fprintf(stderr,
">");
346 }
while (!
G_gets(answer));
348 if (strlen(answer) == 0)
352 "Parameters to be used are:\n\"%s\"\nIs this correct?",
381 char file[GPATH_MAX];
384 struct gpj_datum_transform_list *current =
NULL, *outputlist =
NULL;
385 struct gpj_datum dstruct;
389 if (dstruct.dx < 99999 && dstruct.dy < 99999 && dstruct.dz < 99999) {
394 current = outputlist =
395 G_malloc(
sizeof(
struct gpj_datum_transform_list));
397 current = current->next =
398 G_malloc(
sizeof(
struct gpj_datum_transform_list));
399 G_asprintf(&(current->params),
"towgs84=%.3f,%.3f,%.3f", dstruct.dx,
400 dstruct.dy, dstruct.dz);
401 G_asprintf(&(current->where_used),
"whole %s region", inputname);
403 "Default 3-Parameter Transformation (May not be optimum for "
404 "older datums; use this only if no more appropriate options "
407 current->count =
count;
408 current->next =
NULL;
416 fd = fopen(file,
"r");
418 G_warning(_(
"Unable to open datum table file <%s>"), file);
422 for (line = 1;
G_getl2(buf,
sizeof(buf), fd); line++) {
423 char name[100], params[1024], where_used[1024], comment[1024];
426 if (*buf ==
'\0' || *buf ==
'#')
429 if (sscanf(buf,
"%99s \"%1023[^\"]\" \"%1023[^\"]\" \"%1023[^\"]\"",
430 name, params, where_used, comment) != 4) {
431 G_warning(_(
"Error in datum table file <%s>, line %d"), file,
440 current = outputlist =
441 G_malloc(
sizeof(
struct gpj_datum_transform_list));
443 current = current->next =
444 G_malloc(
sizeof(
struct gpj_datum_transform_list));
445 current->params =
G_store(params);
446 current->where_used =
G_store(where_used);
447 current->comment =
G_store(comment);
449 current->count =
count;
450 current->next =
NULL;
488 char file[GPATH_MAX];
496 fd = fopen(file,
"r");
498 G_warning(_(
"Unable to open datum table file <%s>"), file);
502 for (line = 1;
G_getl2(buf,
sizeof(buf), fd); line++) {
507 if (*buf ==
'\0' || *buf ==
'#')
510 if (sscanf(buf,
"%s \"%1023[^\"]\" %s dx=%lf dy=%lf dz=%lf",
511 name, descr, ellps, &dx, &dy, &dz) != 6) {
512 G_warning(_(
"Error in datum table file <%s>, line %d"), file,
518 current = outputlist = G_malloc(
sizeof(
struct datum_list));
546 G_free(dstruct->longname);
561 while (dstruct !=
NULL) {
char * G_find_key_value(const char *key, const struct Key_Value *kv)
Find given key.
int G_strcasecmp(const char *x, const char *y)
String compare ignoring case (upper or lower)
sprintf(buf2,"%s", G3D_CATS_ELEMENT)
void G_free(void *buf)
Free allocated memory.
void GPJ_free_datum(struct gpj_datum *dstruct)
Free the memory used for the strings in a gpj_datum struct.
char * G_store(const char *s)
Copy string to allocated memory.
void GPJ_free_datum_transform(struct gpj_datum_transform_list *item)
Free the memory used by a gpj_datum_transform_list struct.
char * G_convert_dirseps_to_host(char *path)
Converts directory separator characters in a string to the native host separator character (/ on Unix...
int G_yes(const char *question, int dflt)
Ask a yes/no question.
int G_free_key_value(struct Key_Value *kv)
Free allocated Key_Value structure.
char * G_tempfile(void)
Returns a temporary file name.
int G_asprintf(char **out, const char *fmt,...)
struct gpj_datum_transform_list * GPJ_get_datum_transform_by_name(const char *inputname)
Internal function to find all possible sets of transformation parameters for a particular datum...
int GPJ_get_datum_by_name(const char *name, struct gpj_datum *dstruct)
Look up a string in datum.table file to see if it is a valid datum name and if so place its informati...
int G_getl2(char *buf, int n, FILE *fd)
gets a line of text from a file of any pedigree
void free_datum_list(struct datum_list *dstruct)
Free the memory used by a datum_list linked list structure.
int GPJ_get_datum_params(char **name, char **params)
Extract the datum transformation-related parameters for the current location.
int G_strip(char *buf)
Removes all leading and trailing white space from string.
struct Key_Value * G_get_projinfo(void)
Gets projection information for location.
struct datum_list * read_datum_table(void)
Read the current GRASS datum.table from disk and store in memory.
char buf[GNAME_MAX+sizeof(G3D_DIRECTORY)+2]
int GPJ__get_datum_params(struct Key_Value *projinfo, char **datumname, char **params)
Extract the datum transformation-related parameters from a set of general PROJ_INFO parameters...
G_warning("category support for [%s] in mapset [%s] %s", name, mapset, type)
int GPJ_get_default_datum_params_by_name(const char *name, char **params)
"Last resort" function to retrieve a "default" set of datum parameters for a datum (N...
char * G_gisbase(void)
top level module directory
int G_system(const char *command)
Run a shell level command.
int GPJ_ask_datum_params(const char *datumname, char **params)
Interactively ask for datum parameters for a particular datum.