Specify units for distance query?

140 views
Skip to first unread message

b...@saharagray.com

unread,
Sep 3, 2013, 6:17:04 PM9/3/13
to geoal...@googlegroups.com
I'm doing a distance query between points, and although the documentation says you can specify units, I haven't been able to figure out how to pass that parameter in. It seems to be using degrees be default. This is what I'm doing:

        user_point = WKTSpatialElement("POINT(%s %s)" % (lon, lat))
        distance_col = Site.center.distance(user_point).label('distance')

        sites = db.session.query(Site, distance_col).\
            join(Site.stories).\
            filter(Site.center.within_distance(user_point, 1)).\
            limit(20)

For both within_distance and distance functions, I would like to specify miles if possible. 

thanks
Ben.

Eric Lemoine

unread,
Sep 4, 2013, 7:35:34 AM9/4/13
to geoal...@googlegroups.com
Hi

What database do you use?

With PostGIS, for , ST_Distance returns a distance in projected units
(those of the spatial reference). For geography units are meters
(which can obviously be converted to miles).

<http://postgis.refractions.net/docs/ST_Distance.html>
<http://postgis.net/docs/ST_DWithin.html>

--
Eric Lemoine

Camptocamp France SAS
Savoie Technolac, BP 352
73377 Le Bourget du Lac, Cedex

Tel : 00 33 4 79 44 44 94
Mail : eric.l...@camptocamp.com
http://www.camptocamp.com

b...@saharagray.com

unread,
Oct 16, 2013, 5:23:58 PM10/16/13
to geoal...@googlegroups.com
Yes, I'm using PostGIS. I actually figured out the problem shortly after posting this. I was using geometry rather than geography column, so it was returning degrees. I converted to a geography column type, and just converted meters to miles manually. Thanks for the reply.
Reply all
Reply to author
Forward
0 new messages