示例#1
0
 def meters(self):
     return units.meters(kilometers=self.kilometers)
示例#2
0
文件: format.py 项目: tlusk/nest-away
HTML_SYMBOLS = {"deg": HTML_DEGREE, "arcmin": HTML_PRIME, "arcsec": HTML_DOUBLE_PRIME}
XML_SYMBOLS = {"deg": XML_DECIMAL_DEGREE, "arcmin": XML_DECIMAL_PRIME, "arcsec": XML_DECIMAL_DOUBLE_PRIME}
ABBR_SYMBOLS = {"deg": ABBR_DEGREE, "arcmin": ABBR_ARCMIN, "arcsec": ABBR_ARCSEC}


def format_degrees(degrees, format=DEGREES_FORMAT, symbols=ASCII_SYMBOLS):
    arcminutes = units.arcminutes(degrees=degrees - int(degrees))
    arcseconds = units.arcseconds(arcminutes=arcminutes - int(arcminutes))
    format_dict = dict(symbols, degrees=degrees, minutes=abs(arcminutes), seconds=abs(arcseconds))
    return format % format_dict


DISTANCE_FORMAT = "%(magnitude)s%(unit)s"
DISTANCE_UNITS = {
    "km": lambda d: d,
    "m": lambda d: units.meters(kilometers=d),
    "mi": lambda d: units.miles(kilometers=d),
    "ft": lambda d: units.feet(kilometers=d),
    "nm": lambda d: units.nautical(kilometers=d),
    "nmi": lambda d: units.nautical(kilometers=d),
}


def format_distance(kilometers, format=DISTANCE_FORMAT, unit="km"):
    magnitude = DISTANCE_UNITS[unit](kilometers)
    return format % {"magnitude": magnitude, "unit": unit}


_DIRECTIONS = [
    ("north", "N"),
    ("north by east", "NbE"),
示例#3
0
 def meters(self):
     return units.meters(kilometers=self.kilometers)
示例#4
0
文件: format.py 项目: tlusk/nest-away
def format_degrees(degrees, format=DEGREES_FORMAT, symbols=ASCII_SYMBOLS):
    arcminutes = units.arcminutes(degrees=degrees - int(degrees))
    arcseconds = units.arcseconds(arcminutes=arcminutes - int(arcminutes))
    format_dict = dict(
        symbols,
        degrees=degrees,
        minutes=abs(arcminutes),
        seconds=abs(arcseconds)
    )
    return format % format_dict

DISTANCE_FORMAT = "%(magnitude)s%(unit)s"
DISTANCE_UNITS = {
    'km': lambda d: d,
    'm': lambda d: units.meters(kilometers=d),
    'mi': lambda d: units.miles(kilometers=d),
    'ft': lambda d: units.feet(kilometers=d),
    'nm': lambda d: units.nautical(kilometers=d),
    'nmi': lambda d: units.nautical(kilometers=d)
}
def format_distance(kilometers, format=DISTANCE_FORMAT, unit='km'):
    magnitude = DISTANCE_UNITS[unit](kilometers)
    return format % {'magnitude': magnitude, 'unit': unit}

_DIRECTIONS = [
    ('north', 'N'),
    ('north by east', 'NbE'),
    ('north-northeast', 'NNE'),
    ('northeast by north', 'NEbN'),
    ('northeast', 'NE'),