4 @brief Units management
6 @todo Probably will be replaced by Python ctypes fns in the near
11 from core.units import Units
17 (C) 2009, 2011 by the GRASS Development Team
19 This program is free software under the GNU General Public License
20 (>=v2). Read the file COPYING that comes with GRASS for details.
22 @author Martin Landa <landa.martin gmail.com>
28 self.
_units[
'length'] = { 0 : {
'key' :
'mu',
'label' : _(
'map units') },
29 1 : {
'key' :
'me',
'label' : _(
'meters') },
30 2 : {
'key' :
'km',
'label' : _(
'kilometers') },
31 3 : {
'key' :
'mi',
'label' : _(
'miles') },
32 4 : {
'key' :
'ft',
'label' : _(
'feet') } }
34 self.
_units[
'area'] = { 0 : {
'key' :
'mu',
'label' : _(
'sq map units') },
35 1 : {
'key' :
'me',
'label' : _(
'sq meters') },
36 2 : {
'key' :
'km',
'label' : _(
'sq kilometers') },
37 3 : {
'key' :
'ar',
'label' : _(
'acres') },
38 4 : {
'key' :
'ht',
'label' : _(
'hectares') } }
41 """!Get list of units (their labels)
43 @param type units type ('length' or 'area')
45 @return list of units labels
49 keys = self.
_units[type].keys()
52 result.append(self.
_units[type][idx][
'label'])
59 """!Get units key based on index
61 @param type units type ('length' or 'area')
62 @param index units index
64 return self.
_units[type][index][
'key']
67 """!Get units index based on key
69 @param type units type ('length' or 'area')
70 @param key units key, e.g. 'me' for meters
74 for k, u
in self.
_units[type].iteritems():
82 """!Convert value from map units to given units
84 Inspired by vector/v.to.db/units.c
86 @param value value to be converted
87 @param type units type ('length', 'area')
88 @param unit destination units
100 f = 6.21371192237334e-4
109 f = 3.86102158542446e-7
113 f = 2.47105381467165e-4
def GetUnitsIndex
Get units index based on key.
def GetUnitsList
Get list of units (their labels)
def GetUnitsKey
Get units key based on index.
def ConvertValue
Convert value from map units to given units.