From 0726782ee849e246b3898d0e088ad48f28d02d52 Mon Sep 17 00:00:00 2001 From: XANTRONIX Industrial Date: Tue, 11 Feb 2025 12:10:17 -0500 Subject: [PATCH] Refactor radar distance search to match whole storm path --- lib/nexrad/storm.py | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/lib/nexrad/storm.py b/lib/nexrad/storm.py index dfa56e3..4599e9c 100644 --- a/lib/nexrad/storm.py +++ b/lib/nexrad/storm.py @@ -118,17 +118,29 @@ class StormReport(): select id, call, - ST_Distance(coord, MakePoint(?, ?, %d), true) as distance + ST_Distance(coord, + MakeLine(MakePoint(?, ?, {csr}), + MakePoint(?, ?, {csr})), true) as distance from nexrad_radar where - distance <= 460000 + distance <= 230000 order by distance asc - limit 3 - """ % (COORD_SYSTEM) + """.format(csr=COORD_SYSTEM) - st = db.execute(sql, (self.coord_start.lon, - self.coord_start.lat)) + radars = list() - return st.fetchone() + st = db.execute(sql, ( + self.coord_start.lon, self.coord_start.lat, + self.coord_end.lon, self.coord_end.lat)) + + while True: + radar = st.fetchone() + + if radar is None: + break + + radars.append(radar) + + return radars