能否请您帮我编写正确的SQLAlchemy过滤器以按经度和纬度查找区域?
这是postgres表:
\d geo_table;
Materialized view "public.geo_table"
Column | Type | Collation | Nullable | Default
--------+-------------------------+-----------+----------+---------
id | text | | |
geog | geography(Polygon,4283) | | |
name | text | | |
我需要使用SQLAlchemy来实现相同的选择:
SELECT ce_pid, name FROM geo_table WHERE ST_Within(ST_SetSRID(ST_POINT(149.14668176,-35.32202098),4283), geog::geometry);
from sqlalchemy import func
class SpatialModel(Base):
__tablename__ = 'geo_table'
id = Column(String, primary_key=True)
name = Column(String)
geog = Column(Geometry('Point', 4283))
def get_area(longitude, latitude)
with closing(CustomSession()) as session:
return session.query(SpatialModel).filter(func.ST_Within(SpatialModel.geog, func.ST_POINT(longitude, latitude, 4283)))