From 2a43e7f379297ce103dc98a1e3b9e5aed294076c Mon Sep 17 00:00:00 2001 From: XANTRONIX Industrial Date: Mon, 31 Mar 2025 12:38:27 -0400 Subject: [PATCH] Fix City.each_within_poly() --- lib/xmet/city.py | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/lib/xmet/city.py b/lib/xmet/city.py index 4ab0fda..41df9e8 100644 --- a/lib/xmet/city.py +++ b/lib/xmet/city.py @@ -1,14 +1,14 @@ import csv import shapely -from xmet.db import Database +from xmet.db import Database, DatabaseTable, DatabaseOrder from xmet.coord import COORD_SYSTEM """ Implements a parser and wrapper class for a TSV list of cities. """ -class City(): +class City(DatabaseTable): __slots__ = ( 'id', 'name', 'state', 'population', 'location' ) @@ -65,19 +65,12 @@ class City(): @staticmethod def each_within_poly(db: Database, poly: shapely.Polygon): - sql = """ - select - * - from - xmet_city - where - ST_Within(location, GeomFromText(:poly, 4326)) = 1 - order by - population desc - """ - - st = db.query_sql(City, sql, { + st = db.query(City, [ + 'ST_Within(location, GeomFromText(:poly, 4326)) = 1' + ], { 'poly': shapely.to_wkt(poly) - }) + }, [ + ('population', DatabaseOrder.DESC) + ]) yield from st.each()