Fix City.each_within_poly()
This commit is contained in:
parent
8668b3b4a5
commit
2a43e7f379
1 changed files with 8 additions and 15 deletions
|
@ -1,14 +1,14 @@
|
||||||
import csv
|
import csv
|
||||||
import shapely
|
import shapely
|
||||||
|
|
||||||
from xmet.db import Database
|
from xmet.db import Database, DatabaseTable, DatabaseOrder
|
||||||
from xmet.coord import COORD_SYSTEM
|
from xmet.coord import COORD_SYSTEM
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Implements a parser and wrapper class for a TSV list of cities.
|
Implements a parser and wrapper class for a TSV list of cities.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
class City():
|
class City(DatabaseTable):
|
||||||
__slots__ = (
|
__slots__ = (
|
||||||
'id', 'name', 'state', 'population', 'location'
|
'id', 'name', 'state', 'population', 'location'
|
||||||
)
|
)
|
||||||
|
@ -65,19 +65,12 @@ class City():
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def each_within_poly(db: Database, poly: shapely.Polygon):
|
def each_within_poly(db: Database, poly: shapely.Polygon):
|
||||||
sql = """
|
st = db.query(City, [
|
||||||
select
|
'ST_Within(location, GeomFromText(:poly, 4326)) = 1'
|
||||||
*
|
], {
|
||||||
from
|
|
||||||
xmet_city
|
|
||||||
where
|
|
||||||
ST_Within(location, GeomFromText(:poly, 4326)) = 1
|
|
||||||
order by
|
|
||||||
population desc
|
|
||||||
"""
|
|
||||||
|
|
||||||
st = db.query_sql(City, sql, {
|
|
||||||
'poly': shapely.to_wkt(poly)
|
'poly': shapely.to_wkt(poly)
|
||||||
})
|
}, [
|
||||||
|
('population', DatabaseOrder.DESC)
|
||||||
|
])
|
||||||
|
|
||||||
yield from st.each()
|
yield from st.each()
|
||||||
|
|
Loading…
Add table
Reference in a new issue