How to convert geometry to geography in filter

39 views
Skip to first unread message

Brian Clark

unread,
Jun 2, 2016, 5:44:35 AM6/2/16
to GeoAlchemy
I have a SQL query that looks like this ST_DWithin(locations.point::geography, ST_GeomFromText('POINT(42.331680297851563 -83.0479965209961)',4326), 81000)

How do I get the "::geography" to occur via geoalchemy?

I have this

search_query.join(Location).filter(db.func.ST_DWithin(Location.point, point, meter_distance))

but the query comes out using geometry points and I'd like geography.

Thanks!

Eric Reichwaldt

unread,
Sep 9, 2019, 7:12:00 AM9/9/19
to GeoAlchemy
I just asked the same question before I saw this one (was searching for ST_Buffer...) Where you able to ever figure this out?

eric.l...@gmail.com

unread,
Sep 9, 2019, 12:11:02 PM9/9/19
to geoal...@googlegroups.com
On Mon, Sep 9, 2019 at 1:12 PM Eric Reichwaldt
<eric.re...@gmail.com> wrote:
>
> I just asked the same question before I saw this one (was searching for ST_Buffer...) Where you able to ever figure this out?

Have you tried "cast"?

Example:

from geoalchemy2 import Geography

q = Session.query(Location).filter(
func.ST_DWithin(cast(Location.geom, Geography("POINT", 4326)),
func.ST_GeomFromText("POINT(0 0)", 4326), 10 ) )




--
Eric
Reply all
Reply to author
Forward
0 new messages