19#include <grass/glocale.h>
21static const char *lookup_proj(
const char *);
22static const char *lookup_units(
const char *);
23static const char *lookup_epsg(
void);
24static int equal(
const char *,
const char *);
25static int lower(
char);
27static int initialized;
28static struct Key_Value *proj_info, *proj_units, *proj_epsg;
73 if (units == U_UNDEFINED) {
74 name = lookup_units(
"unit");
78 if (strcasecmp(
name,
"meter") == 0 || strcasecmp(
name,
"metre") == 0 ||
79 strcasecmp(
name,
"meters") == 0 || strcasecmp(
name,
"metres") == 0)
81 else if (strcasecmp(
name,
"kilometer") == 0 ||
82 strcasecmp(
name,
"kilometre") == 0 ||
83 strcasecmp(
name,
"kilometers") == 0 ||
84 strcasecmp(
name,
"kilometres") == 0)
86 else if (strcasecmp(
name,
"acre") == 0 ||
87 strcasecmp(
name,
"acres") == 0)
89 else if (strcasecmp(
name,
"hectare") == 0 ||
90 strcasecmp(
name,
"hectares") == 0)
92 else if (strcasecmp(
name,
"mile") == 0 ||
93 strcasecmp(
name,
"miles") == 0)
95 else if (strcasecmp(
name,
"foot") == 0 || strcasecmp(
name,
"feet") == 0)
97 else if (strcasecmp(
name,
"foot_us") == 0 ||
98 strcasecmp(
name,
"foot_uss") == 0)
100 else if (strcasecmp(
name,
"degree") == 0 ||
101 strcasecmp(
name,
"degrees") == 0)
130 name = lookup_proj(
"name");
132 return _(
"Unknown projection");
154 static const struct {
157 } table[] = {{
"unit", 1.0}, {
"meter", 1.0},
158 {
"foot", .3048}, {
"foot_us", 1200 / 3937.},
159 {
"inch", .0254}, {
NULL, 0.0}};
162 buf = lookup_units(
"meters");
164 sscanf(buf,
"%lf", &factor);
167 for (n = 0; table[n].unit; n++)
168 if (equal(unit, table[n].unit)) {
169 factor = table[n].factor;
189 char buf[256], params[256];
192 name = lookup_proj(
"datum");
200 if (datumstatus == 2)
216 name = lookup_proj(
"ellps");
222 sprintf(buf,
"a=%.16g es=%.16g", a, es);
238 return lookup_epsg();
241const char *lookup_proj(
const char *key)
247const char *lookup_units(
const char *key)
253const char *lookup_epsg(
void)
259int equal(
const char *a,
const char *
b)
264 if (lower(*a++) != lower(*
b++))
273 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_projepsg(void)
Gets EPSG information for the current location.
struct Key_Value * G_get_projunits(void)
Gets units information for 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.
double G_database_units_to_meters_factor(void)
Conversion to meters.
const char * G_database_datum_name(void)
Get datum name for the current location.
const char * G_database_ellipse_name(void)
Get ellipsoid name for the current location.
int G_database_unit(void)
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_projection_name(void)
Query cartographic projection 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.