Skip to content

GeoCoords

Represents a validated WGS-84 geographic coordinate pair.

from geodata.utils.geocoords import GeoCoords

Constructor

GeoCoords(lat: float, lon: float)
Parameter Valid range Description
lat [-90, 90] Latitude in decimal degrees
lon [-180, 180] Longitude in decimal degrees

Values are coerced to float automatically. Invalid types raise TypeError; out-of-range values raise ValueError.


Attributes

Attribute Type Description
lat float Latitude
lon float Longitude

Alternative constructors

from_tuple

@staticmethod
def from_tuple(coords: tuple[float, float]) -> GeoCoords
p = GeoCoords.from_tuple((-15.7801, -47.9292))

from_dict

@staticmethod
def from_dict(data: dict[str, float]) -> GeoCoords
p = GeoCoords.from_dict({"lat": -15.7801, "lon": -47.9292})

from_utm

@staticmethod
def from_utm(easting: float, northing: float, source_crs: str) -> GeoCoords
p = GeoCoords.from_utm(197055.0, 8254536.0, "EPSG:32722")

This method converts projected coordinates to latitude and longitude using pyproj.


Serialisation

to_tuple

(-15.7801, -47.9292) == GeoCoords(lat=-15.7801, lon=-47.9292).to_tuple()

to_dict

{"lat": -15.7801, "lon": -47.9292} == GeoCoords(lat=-15.7801, lon=-47.9292).to_dict()

to_utm

easting, northing = GeoCoords(lat=-15.7801, lon=-47.9292).to_utm("EPSG:32722")

target_crs may be any CRS string accepted by pyproj.

to_shapely_point

point = GeoCoords(lat=-15.7801, lon=-47.9292).to_shapely_point()
# POINT (-47.9292 -15.7801)

Geodesic calculations

distance_to

Great-circle distance in km using the Haversine formula.

brasilia = GeoCoords(lat=-15.7801, lon=-47.9292)
manaus   = GeoCoords(lat=-3.1190,  lon=-60.0217)

print(brasilia.distance_to(manaus))  # ~2689.6 km

bearing_to

Initial bearing in degrees (0–360°), measured clockwise from true north.

print(brasilia.bearing_to(manaus))  # ~322.0°

Notes

  • Coordinates are always stored internally as decimal degrees in WGS-84.
  • to_shapely_point() returns a Point(lon, lat), which matches GIS axis order.
  • CRS transformers are cached internally to reduce repeated conversion overhead.

String representation

str(GeoCoords(lat=-15.7801, lon=-47.9292))
# '15.780100°S, 47.929200°W'