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()