GRASS GIS 8 Programmer's Manual  8.5.0dev(2024)-f622271e7a
units.c File Reference

GIS Library - Units management and conversion. More...

#include <string.h>
#include <grass/gis.h>
#include <grass/glocale.h>
Include dependency graph for units.c:

Go to the source code of this file.

Functions

double G_meters_to_units_factor (int units)
 Units conversion from meters to units. More...
 
double G_meters_to_units_factor_sq (int units)
 Units conversion from square meters to square units. More...
 
int G_is_units_type_spatial (int units)
 Check if the unit is of spatial type. More...
 
int G_is_units_type_temporal (int units)
 Check if the unit is of temporal type. More...
 
const char * G_get_units_name (int units, int plural, int square)
 Get localized units name. More...
 
int G_units (const char *units_name)
 Get units code by name. More...
 

Detailed Description

GIS Library - Units management and conversion.

(C) 2001-2010 by the GRASS Development Team

This program is free software under the GNU General Public License (>=v2). Read the file COPYING that comes with GRASS for details.

Author
Original author CERL
Adopted for libgis by Martin Landa <landa.martin gmail.com> (2010)
Temporal units and unit type check from Soeren gebbert <soerengebbert googlemail.com> (2012)

Definition in file units.c.

Function Documentation

◆ G_get_units_name()

const char* G_get_units_name ( int  units,
int  plural,
int  square 
)

Get localized units name.

Units codes (gis.h):

  • U_METERS
  • U_KILOMETERS
  • U_ACRES
  • U_HECTARES
  • U_MILES
  • U_FEET
  • U_USFEET
Parameters
unitsunits code
pluralplural form if true
squarearea units if true
Returns
units name
NULL if units not found

Definition at line 204 of file units.c.

References _, G_database_unit_name(), G_get_units_name(), G_units(), NULL, U_ACRES, U_DAYS, U_DEGREES, U_FEET, U_HECTARES, U_HOURS, U_KILOMETERS, U_METERS, U_MILES, U_MINUTES, U_MONTHS, U_SECONDS, U_UNKNOWN, U_USFEET, and U_YEARS.

Referenced by G_database_unit_name(), G_get_units_name(), Rast3d_get_vertical_unit(), and Rast3d_print_header().

◆ G_is_units_type_spatial()

int G_is_units_type_spatial ( int  units)

Check if the unit is of spatial type.

Parameters
unitsunits code from gis.h
Returns
1 if True, 0 otherwise

Definition at line 134 of file units.c.

References U_ACRES, U_DEGREES, U_FEET, U_HECTARES, U_KILOMETERS, U_METERS, U_MILES, U_RADIANS, and U_USFEET.

◆ G_is_units_type_temporal()

int G_is_units_type_temporal ( int  units)

Check if the unit is of temporal type.

Parameters
unitsunits code from gis.h
Returns
1 if True, 0 otherwise

Definition at line 166 of file units.c.

References U_DAYS, U_HOURS, U_MINUTES, U_MONTHS, U_SECONDS, and U_YEARS.

◆ G_meters_to_units_factor()

double G_meters_to_units_factor ( int  units)

Units conversion from meters to units.

Units codes (gis.h):

  • U_METERS
  • U_KILOMETERS
  • U_MILES
  • U_FEET
  • U_USFEET

Returns a factor which converts meters to units (by multiplication).

Parameters
unitsunits code
Returns
factor

Definition at line 38 of file units.c.

References U_FEET, U_KILOMETERS, U_METERS, U_MILES, and U_USFEET.

◆ G_meters_to_units_factor_sq()

double G_meters_to_units_factor_sq ( int  units)

Units conversion from square meters to square units.

Units codes (gis.h):

  • U_METERS
  • U_KILOMETERS
  • U_ACRES
  • U_HECTARES
  • U_MILES
  • U_FEET
  • U_USFEET

Returns a factor which converts square meters to square units (by multiplication).

Parameters
unitsunits code
Returns
factor

Definition at line 88 of file units.c.

References U_ACRES, U_FEET, U_HECTARES, U_KILOMETERS, U_METERS, U_MILES, and U_USFEET.

◆ G_units()

int G_units ( const char *  units_name)

Get units code by name.

Units codes (gis.h):

  • U_METERS
  • U_KILOMETERS
  • U_ACRES
  • U_HECTARES
  • U_MILES
  • U_FEET
  • U_USFEET
  • ...
  • U_YEARS
  • ...
Parameters
units_nameunits name (singular or plural form)
Returns
units code
U_UNKNOWN if not found

Definition at line 320 of file units.c.

References G_database_unit_name(), G_units(), NULL, U_ACRES, U_DAYS, U_DEGREES, U_FEET, U_HECTARES, U_HOURS, U_KILOMETERS, U_METERS, U_MILES, U_MINUTES, U_MONTHS, U_SECONDS, U_UNKNOWN, U_USFEET, and U_YEARS.

Referenced by G_get_units_name(), G_units(), and Rast3d_set_vertical_unit().