Tools to handle representations of geographic coordinates
Functionality to convert between different representations of geo-coordinates.
In particular, we support conversion of coordinates in the notation used for the World Atlas of Language Structures, e.g. (12d10N, 92d49E), to floating point latitude and longitude values.
- class clldutils.coordinates.Coordinates(lat, lon, format=CoordinateFormat.alnum)[source]
A (lat, lon) pair, that can be represented in various formats.
>>> c = Coordinates('13dN', 0) >>> assert c.latitude >= 13 >>> assert c.latitude <= 13.1 >>> c = Coordinates(0, 0) >>> assert c.lat_to_string() == '0dN' >>> assert c.lon_to_string() == '0dE' >>> c = Coordinates(12.17, 92.83) >>> assert c.lat_to_string() == '12d10N' >>> assert c.lon_to_string() == '92d49E' >>> c = Coordinates(-12.17, -92.83) >>> assert c.lat_to_string() == '12d10S' >>> c.lat_to_string(format=None) '12° 10′ 12″ S' >>> c.lat_to_string(format=CoordinateFormat.ascii) '12°10'12.000000"S' >>> assert c.lon_to_string() == '92d49W' >>> lat, lon = '12d30N', '60d30E' >>> c = Coordinates(lat, lon) >>> assert c.lat_to_string() == lat >>> assert c.lon_to_string() == lon
- Parameters:
lat (
typing.Union[str,int,float]) –lon (
typing.Union[str,int,float]) –format (
typing.Union[clldutils.coordinates.CoordinateFormat,str]) –
- lat_from_string(lat, format=CoordinateFormat.alnum)[source]
Parse a latitude value.
- Parameters:
lat (
str) –format (
clldutils.coordinates.CoordinateFormat) –
- Return type:
float
- lon_from_string(lon, format=CoordinateFormat.alnum)[source]
Parse a longitude value.
- Parameters:
lon (
str) –format (
clldutils.coordinates.CoordinateFormat) –
- Return type:
float
- clldutils.coordinates.dec2degminsec(dec, no_seconds=False)[source]
convert a floating point number of degrees to a triple (int degrees, int minutes, float seconds)
>>> assert dec2degminsec(30.50) == (30, 30, 0.0)
- Parameters:
dec (
float) –no_seconds (
bool) –
- Return type:
tuple[int,int,float]
- clldutils.coordinates.degminsec2dec(degrees, minutes, seconds)[source]
convert a triple (int degrees, int minutes, float seconds) to a floating point number of degrees
>>> assert dec2degminsec(degminsec2dec(30,30,0.0)) == (30,30,0.0)
- Parameters:
degrees (
int) –minutes (
int) –seconds (
float) –
- Return type:
float