15 #include <grass/gis.h>
16 #include <grass/glocale.h>
18 static const char *lookup_proj(
const char *);
19 static const char *lookup_units(
const char *);
20 static const char *lookup_epsg();
21 static int equal(
const char *,
const char *);
22 static int lower(
char);
24 static int initialized;
25 static struct Key_Value *proj_info, *proj_units, *proj_epsg;
27 static void init(
void)
57 if (units == U_UNDEFINED) {
58 name = lookup_units(plural ?
"units" :
"unit");
60 return plural ? _(
"units") : _(
"unit");
62 if (strcasecmp(name,
"meter") == 0 || strcasecmp(name,
"metre") == 0
63 || strcasecmp(name,
"meters") == 0 || strcasecmp(name,
"metres") == 0)
65 else if (strcasecmp(name,
"kilometer") == 0 || strcasecmp(name,
"kilometre") == 0
66 || strcasecmp(name,
"kilometers") == 0 || strcasecmp(name,
"kilometres") == 0)
68 else if (strcasecmp(name,
"acre") == 0 || strcasecmp(name,
"acres") == 0)
70 else if (strcasecmp(name,
"hectare") == 0 || strcasecmp(name,
"hectares") == 0)
72 else if (strcasecmp(name,
"mile") == 0 || strcasecmp(name,
"miles") == 0)
74 else if (strcasecmp(name,
"foot") == 0 || strcasecmp(name,
"feet") == 0)
76 else if (strcasecmp(name,
"foot_us") == 0 || strcasecmp(name,
"foot_uss") == 0)
78 else if (strcasecmp(name,
"degree") == 0 || strcasecmp(name,
"degrees") == 0)
108 name = lookup_proj(
"name");
110 return _(
"Unknown projection");
140 {
"foot_us", 1200/3937.},
146 buf = lookup_units(
"meters");
148 sscanf(buf,
"%lf", &factor);
151 for (n = 0; table[n].unit; n++)
152 if (equal(unit, table[n].unit)) {
153 factor = table[n].factor;
173 char buf[256], params[256];
176 name = lookup_proj(
"datum");
184 if (datumstatus == 2)
200 name = lookup_proj(
"ellps");
206 sprintf(buf,
"a=%.16g es=%.16g", a, es);
222 return lookup_epsg();
225 const char *lookup_proj(
const char *key)
231 const char *lookup_units(
const char *key)
237 const char *lookup_epsg()
243 int equal(
const char *a,
const char *
b)
248 if (lower(*a++) != lower(*b++))
257 if (c >=
'A' && c <=
'Z')
const char * G_database_datum_name(void)
Get datum name for the current location.
const char * G_find_key_value(const char *key, const struct Key_Value *kv)
Find given key (case sensitive)
int G_get_datumparams_from_projinfo(const struct Key_Value *projinfo, char *datumname, char *params)
struct Key_Value * G_get_projunits(void)
Gets units information for location.
const char * G_database_ellipse_name(void)
Get ellipsoid name for the current location.
const char * G_projection_name(int n)
Get projection name.
const char * G_database_epsg_code(void)
Get EPGS code for the current location.
char * G_store(const char *s)
Copy string to allocated memory.
int G_get_ellipsoid_parameters(double *a, double *e2)
get ellipsoid parameters
int G_is_initialized(int *p)
void G_initialize_done(int *p)
int G_projection_units(int n)
Get projection units code (for internal use only)
struct Key_Value * G_get_projinfo(void)
Gets projection information for location.
const char * G_database_projection_name(void)
Query cartographic projection for the current location.
struct Key_Value * G_get_projepsg(void)
Gets EPSG information for the current location.
const char * G_get_units_name(int units, int plural, int square)
Get localized units name.
double G_database_units_to_meters_factor(void)
Conversion to meters.
int G_projection(void)
Query cartographic projection.
const char * G_database_unit_name(int plural)
Get units (localized) name for the current location.