21 #include <grass/gis.h> 22 #include <grass/glocale.h> 23 #include <grass/gprojects.h> 24 #include "local_proto.h" 39 struct datum_list *
list, *listhead;
43 while (list !=
NULL) {
45 dstruct->name =
G_store(list->name);
46 dstruct->longname =
G_store(list->longname);
47 dstruct->ellps =
G_store(list->ellps);
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 const char *projshare = getenv(
"GRASS_PROJSHARE");
195 G_warning(_(
"Failed to detect nadgrids path, GRASS_PROJSHARE not defined"));
199 G_asprintf(params,
"nadgrids=%s%c%s", projshare, HOST_DIRSEP,
241 char file[GPATH_MAX];
244 struct gpj_datum_transform_list *current =
NULL, *outputlist =
NULL;
245 struct gpj_datum dstruct;
249 if (dstruct.dx < 99999 && dstruct.dy < 99999 && dstruct.dz < 99999) {
254 current = outputlist =
255 G_malloc(
sizeof(
struct gpj_datum_transform_list));
257 current = current->next =
258 G_malloc(
sizeof(
struct gpj_datum_transform_list));
259 G_asprintf(&(current->params),
"towgs84=%.3f,%.3f,%.3f", dstruct.dx,
260 dstruct.dy, dstruct.dz);
261 G_asprintf(&(current->where_used),
"whole %s region", inputname);
263 "Default 3-Parameter Transformation (May not be optimum for " 264 "older datums; use this only if no more appropriate options " 267 current->count =
count;
268 current->next =
NULL;
274 sprintf(file,
"%s%s",
G_gisbase(), DATUMTRANSFORMTABLE);
276 fd = fopen(file,
"r");
278 G_warning(_(
"Unable to open datum table file <%s>"), file);
282 for (line = 1;
G_getl2(buf,
sizeof(buf), fd); line++) {
283 char name[100], params[1024], where_used[1024], comment[1024];
286 if (*buf ==
'\0' || *buf ==
'#')
289 if (sscanf(buf,
"%99s \"%1023[^\"]\" \"%1023[^\"]\" \"%1023[^\"]\"",
290 name, params, where_used, comment) != 4) {
291 G_warning(_(
"Error in datum table file <%s>, line %d"), file,
300 current = outputlist =
301 G_malloc(
sizeof(
struct gpj_datum_transform_list));
303 current = current->next =
304 G_malloc(
sizeof(
struct gpj_datum_transform_list));
305 current->params =
G_store(params);
306 current->where_used =
G_store(where_used);
307 current->comment =
G_store(comment);
309 current->count =
count;
310 current->next =
NULL;
348 char file[GPATH_MAX];
351 struct datum_list *current =
NULL, *outputlist =
NULL;
356 fd = fopen(file,
"r");
358 G_warning(_(
"Unable to open datum table file <%s>"), file);
362 for (line = 1;
G_getl2(buf,
sizeof(buf), fd); line++) {
363 char name[100], descr[1024], ellps[100];
367 if (*buf ==
'\0' || *buf ==
'#')
370 if (sscanf(buf,
"%s \"%1023[^\"]\" %s dx=%lf dy=%lf dz=%lf",
371 name, descr, ellps, &dx, &dy, &dz) != 6) {
372 G_warning(_(
"Error in datum table file <%s>, line %d"), file,
378 current = outputlist = G_malloc(
sizeof(
struct datum_list));
380 current = current->next = G_malloc(
sizeof(
struct datum_list));
382 current->longname =
G_store(descr);
383 current->ellps =
G_store(ellps);
387 current->next =
NULL;
406 G_free(dstruct->longname);
419 struct datum_list *old;
421 while (dstruct !=
NULL) {
423 G_free(dstruct->longname);
int G_strcasecmp(const char *x, const char *y)
String compare ignoring case (upper or lower)
const char * G_find_key_value(const char *key, const struct Key_Value *kv)
Find given key (case sensitive)
void GPJ_free_datum(struct gpj_datum *dstruct)
Free the memory used for the strings in a gpj_datum struct.
int GPJ__get_datum_params(const struct Key_Value *projinfo, char **datumname, char **params)
Extract the datum transformation-related parameters from a set of general PROJ_INFO parameters...
void G_strip(char *buf)
Removes all leading and trailing white space from string.
void GPJ_free_datum_transform(struct gpj_datum_transform_list *item)
Free the memory used by a gpj_datum_transform_list struct.
char * G_store(const char *s)
Copy string to allocated memory.
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...
void G_free_key_value(struct Key_Value *kv)
Free allocated Key_Value structure.
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_debug(int level, const char *msg,...)
Print debugging message.
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.
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...
void G_free(void *buf)
Free allocated memory.
const char * G_gisbase(void)
Get full path name of the top level module directory.
void G_warning(const char *msg,...)
Print a warning message to stderr.