jgdtrans.dms module#

Provides utilities.

jgdtrans.dms.to_dms(t: float) str#

Returns a DMS notation str from a DD notation float.

Parameters:

t – the DD notation latitude or longitude which satisfies -180.0 <= and 180.0

Returns:

t as a DMS notation

Raises:

ValueError – when conversion failed

Examples

>>> to_dms(36.103774791666666)
"360613.589250000023299"
>>> to_dms(140.08785504166667)
"1400516.278150000016467"
jgdtrans.dms.from_dms(s: str) float#

Returns a DD notation float from a DMS notation str.

Parameters:

s – the DMS notation latitude or longitude

Returns:

s as a DD notation float

Raises:

ValueError – when conversion failed

Examples

>>> from_dms("360613.58925")
36.103774791666666
>>> from_dms("1400516.27815")
140.08785504166664
class jgdtrans.dms.DMS(sign: Literal[1, -1], degree: int, minute: int, second: int, fract: float)#

Bases: object

Represents latitude and/or longitude in DMS notation.

Raises:

ValueError – when all the following conditions does not hold; - degree satisries 0 <= and <= 180, - minute does 0 <= and < 60, - second does 0 <= and < 60, - and fract does 0.0 <= and < 1.0. - Additionally, minute, second and fract is 0 when degree is 180.

Examples

>>> dms = DMS(1, 36, 6, 13, 0.58925)
>>> dms
DMS(sign=1, degree=36, minute=6, second=13, fract=0.58925)
>>> dms.sign, dms.degree, dms.minute, dms.second, dms.fract
(1, 36, 6, 13, 0.58925)
>>> dms.to_str()
"360613.58925"
>>> dms.to_dd()
36.10377479166667
>>> DMS.from_dd(36.10377479166667)
DMS(sign=1, degree=36, minute=6, second=13, fract=0.58925)
sign: Literal[1, -1]#

The sign of latitude or longitude.

degree: int#

The degree of latitude or longitude.

minute: int#

The minute of latitude or longitude.

second: int#

The integer part of second of latitude or longitude.

fract: float#

The fraction part of second of latitude or longitude.

classmethod from_str(s: str) Self#

Makes a DMS obj from DMS notation str.

Parameters:

s – latitude or longitude in DMS notation

Returns:

a DMS obj

Raises:

ValueError – when s is invalid or out-of-range

Examples

>>> DMS.from_str("360613.58925")
DMS(sign=1, degree=36, minute=6, second=13, fract=0.58925)
>>> DMS.from_str("1400516.27815")
DMS(sign=1, degree=140, minute=5, second=16, fract=0.27815)
classmethod from_dd(t: float) Self#

Makes a DMS obj from DD notation float.

Parameters:

t – the latitude or longitude which satisfies -180.0 <= and <= 180.0

Returns:

a DMS obj

Raises:

ValueError – when t is out-of-range

Examples

>>> DMS.from_dd(36.103774791666666)
DMS(sign=1, degree=36, minute=6, second=13, fract=0.5892500000232985)
>>> DMS.from_dd(140.08785504166667)
DMS(sign=1, degree=140, minute=5, second=16, fract=0.2781500001187851)
to_str() str#

Returns a DMS notation str obj of self.

Returns:

a DMS notation str obj

Examples

>>> DMS(1, 36, 6, 13, 0.58925).to_str()
"360613.58925"
>>> DMS(1, 140, 5, 16, 0.27815).to_str()
"1400516.27815"
to_primed_str(ascii: bool = False) str#

Returns a DMS notation str obj of self with primes.

Parameters:

ascii – use ascii "'" and '"' for separators

Returns:

a DMS notation str obj

Examples

>>> DMS(1, 36, 6, 13, 0.58925).to_str()
"36°06′13.58925″"
>>> DMS(1, 140, 5, 16, 0.27815).to_str()
"140°05′16.27815″"
to_dd() float#

Returns a DD notation float obj of self.

Returns:

a self in DD notation

Examples

>>> DMS(1, 36, 6, 13, 0.58925).to_dd()
36.103774791666666
>>> DMS(1, 140, 5, 16, 0.27815).to_dd()
140.08785504166667