17 #define DATUMTABLE "/etc/proj/datum.table"
24 #include <grass/gis.h>
25 #include <grass/glocale.h>
43 static int compare_table_names(
const void *,
const void *);
51 for (i = 0; i < table.count; i++)
62 if (n < 0 || n >= table.count)
65 return table.datums[n].name;
72 if (n < 0 || n >= table.count)
75 return table.datums[n].descr;
82 if (n < 0 || n >= table.count)
85 return table.datums[n].ellps;
110 char *datumname,
char *params)
124 sprintf(params,
"nadgrids=%s",
135 sprintf(params,
"towgs84=%s,%s,%s",
149 char file[GPATH_MAX];
158 fd = fopen(
file,
"r");
165 for (line = 1;
G_getl2(buf,
sizeof(buf), fd); line++) {
166 char name[100], descr[100], ellps[100];
170 if (*buf ==
'\0' || *buf ==
'#')
173 if (table.count >= table.size) {
175 table.datums = G_realloc(table.datums, table.size *
sizeof(
struct datum));
178 t = &table.datums[table.count];
180 if (sscanf(buf,
"%s \"%99[^\"]\" %s dx=%lf dy=%lf dz=%lf",
181 name, descr, ellps, &
t->dx, &
t->dy, &
t->dz) != 6) {
182 G_warning(_(
"error in datum table file, line %d"), line);
193 qsort(table.datums, table.count,
sizeof(
struct datum), compare_table_names);
198 static int compare_table_names(
const void *aa,
const void *bb)
200 const struct datum *a = aa;
201 const struct datum *
b = bb;
void G_initialize_done(int *p)
int G_is_initialized(int *p)
int G_getl2(char *buf, int n, FILE *fd)
Gets a line of text from a file of any pedigree.
const char * G_datum_name(int n)
int G_get_datumparams_from_projinfo(const struct Key_Value *projinfo, char *datumname, char *params)
const char * G_datum_description(int n)
const char * G_datum_ellipsoid(int n)
int G_get_datum_by_name(const char *name)
void G_read_datum_table(void)
void G_warning(const char *msg,...)
Print a warning message to stderr.
const char * G_gisbase(void)
Get full path name of the top level module directory.
const char * G_find_key_value(const char *key, const struct Key_Value *kv)
Find given key (case sensitive)
char * G_store(const char *s)
Copy string to allocated memory.
int G_strcasecmp(const char *x, const char *y)
String compare ignoring case (upper or lower)
void G_strip(char *buf)
Removes all leading and trailing white space from string.