I try searching for this problem on the web, but to no avail. Seems like a basic task. I'm using PostGresql through SQLAlchemy with Geoalchemy to do geospatial queries. Technically, I'm using `Flask-SQLAlchemy. I can do a geospatial query. For example:
from geoalchemy2 import func
cls.db.session.query(cls).filter(func.ST_DWithin(cls.geoLoc, geo, meters))
where cls
is the class I'm querying on. geo
is the Geography
point representing the center of the query and meters
is the max distance to return results from. This query works, but returns results in an arbitrary order. I want them returned in increasing (decreasing is fine too) distance from the query point.
I assume I need to use an .order_by(...)
at the end of the query, but I can't figure out what to put in there.