Beispiel #1
0
/*!
  \brief Conversion to meters
  
  Returns a factor which converts the grid unit to meters (by
  multiplication). If the database is not metric (eg. imagery) then
  0.0 is returned.
  
  \return value
*/
double G_database_units_to_meters_factor(void)
{
    const char *unit;
    const char *buf;
    double factor;
    int n;

    /* TODO: sync with definitions in ../proj/units.table */
    static const struct
    {
	char *unit;
	double factor;
    } table[] = {
	{"unit",  1.0},
	{"meter", 1.0},
	{"foot",  .3048},
	{"foot_us", 1200/3937.},
	{"inch", .0254},
	{NULL, 0.0}
    };

    factor = 0.0;
    buf = lookup_units("meters");
    if (buf)
	sscanf(buf, "%lf", &factor);
    if (factor <= 0.0) {
	unit = G_database_unit_name(0);
	for (n = 0; table[n].unit; n++)
	    if (equal(unit, table[n].unit)) {
		factor = table[n].factor;
		break;
	    }
    }
    return factor;
}
Beispiel #2
0
/*!
  \brief Get units id for the current location
  
  \return units id
*/
int G_database_unit()
{
    int units;
    const char *name;
    
    units = G_projection_units(G_projection());
    
    if (units == U_UNDEFINED) {
	name = lookup_units("unit");
	if (!name)
	    return U_UNKNOWN;
	
	if (strcasecmp(name, "meter") == 0 || strcasecmp(name, "metre") == 0 
            || strcasecmp(name, "meters") == 0 || strcasecmp(name, "metres") == 0)
	    units = U_METERS;
	else if (strcasecmp(name, "kilometer") == 0 || strcasecmp(name, "kilometre") == 0
                 || strcasecmp(name, "kilometers") == 0 || strcasecmp(name, "kilometres") == 0)
	    units = U_KILOMETERS;
	else if (strcasecmp(name, "acre") == 0 || strcasecmp(name, "acres") == 0)
	    units = U_ACRES;
	else if (strcasecmp(name, "hectare") == 0 || strcasecmp(name, "hectares") == 0)
	    units = U_HECTARES;
	else if (strcasecmp(name, "mile") == 0 || strcasecmp(name, "miles") == 0)
	    units = U_MILES;
	else if (strcasecmp(name, "foot") == 0 || strcasecmp(name, "feet") == 0)
	    units = U_FEET;
	else if (strcasecmp(name, "foot_us") == 0 || strcasecmp(name, "foot_uss") == 0)
	    units = U_USFEET;
	else if (strcasecmp(name, "degree") == 0 || strcasecmp(name, "degrees") == 0)
	    units = U_DEGREES;
	else
	    units = U_UNKNOWN;
    }
    return units;
}
Beispiel #3
0
/*!
  \brief Get units (localized) name for the current location
  
  Returns a string describing the database grid units. It returns a
  plural form (eg. 'feet') if <i>plural</i> is non-zero. Otherwise it
  returns a singular form (eg. 'foot').
  
  \param plural plural form if non-zero
  
  \return localized units name
*/
const char *G_database_unit_name(int plural)
{
    int units;
    const char *name;
    
    units = G_projection_units(G_projection());
    
    if (units == U_UNDEFINED) {
	name = lookup_units(plural ? "units" : "unit");
	if (!name)
	    return plural ? _("units") : _("unit");
	
	if (strcasecmp(name, "meter") == 0 || strcasecmp(name, "metre") == 0 
            || strcasecmp(name, "meters") == 0 || strcasecmp(name, "metres") == 0)
	    units = U_METERS;
	else if (strcasecmp(name, "kilometer") == 0 || strcasecmp(name, "kilometre") == 0
                 || strcasecmp(name, "kilometers") == 0 || strcasecmp(name, "kilometres") == 0)
	    units = U_KILOMETERS;
	else if (strcasecmp(name, "acre") == 0 || strcasecmp(name, "acres") == 0)
	    units = U_ACRES;
	else if (strcasecmp(name, "hectare") == 0 || strcasecmp(name, "hectares") == 0)
	    units = U_HECTARES;
	else if (strcasecmp(name, "mile") == 0 || strcasecmp(name, "miles") == 0)
	    units = U_MILES;
	else if (strcasecmp(name, "foot") == 0 || strcasecmp(name, "feet") == 0)
	    units = U_FEET;
	else if (strcasecmp(name, "foot_us") == 0 || strcasecmp(name, "foot_uss") == 0)
	    units = U_USFEET;
	else if (strcasecmp(name, "degree") == 0 || strcasecmp(name, "degrees") == 0)
	    units = U_DEGREES;
	else
	    units = U_UNKNOWN;
    }
    
    return G_get_units_name(units, plural, FALSE);
}