我创建了以下SQL查询以查找一英里内的所有用户,并且看来工作正常:
SELECT * FROM user
WHERE ST_DWithin(
user.location,
ST_MakePoint(-2.242631, 53.480759)::geography, 1609)
);
但是我要将其转换为flask / sqlalchemy / geoalchemy查询吗?
答案 0 :(得分:0)
尝试这样的事情:
DISTANCE = 100 #100 meters
db.session.query(User).filter(func.ST_DWithin(User.location, cast(funct.ST_SetSRID(func.ST_MakePoint(-2.242631, 53.480759), 1609), Geography), DISTANCE)).all()