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)
69 if (units == U_UNDEFINED) {
70 name = lookup_units(
"unit");
74 if (strcasecmp(
name,
"meter") == 0 || strcasecmp(
name,
"metre") == 0
75 || strcasecmp(
name,
"meters") == 0 || strcasecmp(
name,
"metres") == 0)
77 else if (strcasecmp(
name,
"kilometer") == 0 || strcasecmp(
name,
"kilometre") == 0
78 || strcasecmp(
name,
"kilometers") == 0 || strcasecmp(
name,
"kilometres") == 0)
80 else if (strcasecmp(
name,
"acre") == 0 || strcasecmp(
name,
"acres") == 0)
82 else if (strcasecmp(
name,
"hectare") == 0 || strcasecmp(
name,
"hectares") == 0)
84 else if (strcasecmp(
name,
"mile") == 0 || strcasecmp(
name,
"miles") == 0)
86 else if (strcasecmp(
name,
"foot") == 0 || strcasecmp(
name,
"feet") == 0)
88 else if (strcasecmp(
name,
"foot_us") == 0 || strcasecmp(
name,
"foot_uss") == 0)
90 else if (strcasecmp(
name,
"degree") == 0 || strcasecmp(
name,
"degrees") == 0)
119 name = lookup_proj(
"name");
121 return _(
"Unknown projection");
151 {
"foot_us", 1200/3937.},
157 buf = lookup_units(
"meters");
159 sscanf(buf,
"%lf", &factor);
162 for (n = 0; table[n].unit; n++)
163 if (equal(unit, table[n].unit)) {
164 factor = table[n].factor;
184 char buf[256], params[256];
187 name = lookup_proj(
"datum");
195 if (datumstatus == 2)
211 name = lookup_proj(
"ellps");
217 sprintf(buf,
"a=%.16g es=%.16g", a, es);
233 return lookup_epsg();
236 const char *lookup_proj(
const char *key)
242 const char *lookup_units(
const char *key)
248 const char *lookup_epsg()
254 int equal(
const char *a,
const char *
b)
259 if (lower(*a++) != lower(*
b++))
268 if (c >=
'A' && c <=
'Z')
void G_initialize_done(int *p)
int G_is_initialized(int *p)
int G_get_ellipsoid_parameters(double *a, double *e2)
get ellipsoid parameters
struct Key_Value * G_get_projinfo(void)
Gets projection information for location.
struct Key_Value * G_get_projunits(void)
Gets units information for location.
struct Key_Value * G_get_projepsg(void)
Gets EPSG information for the current location.
int G_get_datumparams_from_projinfo(const struct Key_Value *projinfo, char *datumname, char *params)
const char * G_find_key_value(const char *key, const struct Key_Value *kv)
Find given key (case sensitive)
int G_projection(void)
Query cartographic projection.
int G_projection_units(int n)
Get projection units code (for internal use only)
const char * G_projection_name(int n)
Get projection name.
const char * G_database_epsg_code(void)
Get EPGS code for the current location.
const char * G_database_projection_name(void)
Query cartographic projection for the current location.
double G_database_units_to_meters_factor(void)
Conversion to meters.
int G_database_unit()
Get units id for the current location.
const char * G_database_unit_name(int plural)
Get units (localized) name for the current location.
const char * G_database_ellipse_name(void)
Get ellipsoid name for the current location.
const char * G_database_datum_name(void)
Get datum name for the current location.
char * G_store(const char *s)
Copy string to allocated memory.
const char * G_get_units_name(int units, int plural, int square)
Get localized units name.