Fix City.each_within_poly()

This commit is contained in:
XANTRONIX 2025-03-31 12:38:27 -04:00
parent 8668b3b4a5
commit 2a43e7f379

View file

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