0

I have created the following SQL query to find all users within a mile and it seems to work fine:

SELECT * FROM user 
WHERE ST_DWithin(
    user.location, 
    ST_MakePoint(-2.242631, 53.480759)::geography, 1609) 
);

However I want to convert this into a flask/sqlalchemy/geoalchemy query?

davidism
  • 121,510
  • 29
  • 395
  • 339
John Mike
  • 1,895
  • 3
  • 17
  • 26

1 Answers1

0

Try something like this:

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()
Jair Perrut
  • 1,360
  • 13
  • 24