From cf00a44bcd0fbb569b3a18bebb372feee9c23e3a Mon Sep 17 00:00:00 2001 From: josidd <joseph.siddons@noc.ac.uk> Date: Thu, 3 Oct 2024 09:11:37 +0100 Subject: [PATCH] feat: add distance method to Record class --- GeoSpatialTools/quadtree.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/GeoSpatialTools/quadtree.py b/GeoSpatialTools/quadtree.py index f58c41c..0dc9420 100644 --- a/GeoSpatialTools/quadtree.py +++ b/GeoSpatialTools/quadtree.py @@ -41,7 +41,7 @@ class Record: return None def __str__(self) -> str: - return f"Record(x = {self.lon}, y = {self.lat}, datetime = {self.datetime}, uid = {self.uid})" + return f"Record(lon = {self.lon}, lat = {self.lat}, datetime = {self.datetime}, uid = {self.uid})" def __eq__(self, other: object) -> bool: return ( @@ -52,6 +52,12 @@ class Record: and (not (self.uid or other.uid) or self.uid == other.uid) ) + def distance(self, other: object) -> float: + """Compute the Haversine distance to another Record""" + if not isinstance(other, Record): + raise TypeError("Argument other must be an instance of Record") + return haversine(self.lon, self.lat, other.lon, other.lat) + class Rectangle: """ -- GitLab