Implement City.each_within_poly()
This commit is contained in:
parent
c4c5336e53
commit
8668b3b4a5
1 changed files with 20 additions and 0 deletions
|
@ -1,6 +1,7 @@
|
||||||
import csv
|
import csv
|
||||||
import shapely
|
import shapely
|
||||||
|
|
||||||
|
from xmet.db import Database
|
||||||
from xmet.coord import COORD_SYSTEM
|
from xmet.coord import COORD_SYSTEM
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
@ -61,3 +62,22 @@ class City():
|
||||||
row[i] = row[i].rstrip()
|
row[i] = row[i].rstrip()
|
||||||
|
|
||||||
yield City.from_tsv_row(row)
|
yield City.from_tsv_row(row)
|
||||||
|
|
||||||
|
@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, {
|
||||||
|
'poly': shapely.to_wkt(poly)
|
||||||
|
})
|
||||||
|
|
||||||
|
yield from st.each()
|
||||||
|
|
Loading…
Add table
Reference in a new issue