[postgis-users] -- Caculating distance from an address --

David William Bitner bitner at gyttja.org
Fri Sep 15 08:30:51 PDT 2006


On 9/15/06, Michael Fuhr <mike at fuhr.org> wrote:
>
> On Fri, Sep 15, 2006 at 07:48:12AM -0700, Rafael Orta wrote:
> > update smarter.vow_properties set geom = makePoint (latitude,
> longitude);
>
> This should be makePoint(longitude, latitude).  Geometries are (X Y).
>
> > Looking for properties in my table that are around 100 metters from a
> point.
> > ==================================================
> > select * from smarter.vow_properties where geom &&
> Expand(GeomFromText('POINT( 39.940252 -074.905868)',-1),100)
> > and Distance (GeomFromText('POINT(39.946788 -074.905868)',-1),geom) <
> 100;
> >
> > What I am doing wrong? No matter what distance I place even 1 metter
> > it return all the rows.



Expand() and Distance() use the same units as the input geometries,
> which in this case is degrees, not meters.  Try expanding by a small
> fraction of a degree (0.002 should be reasonable at that latitude)
> and use distance_sphere() instead of Distance().  Alternatively,
> transform the coordinates to an SRID that uses meter units, such
> as the appropriate UTM zone.
>
> --
> Michael Fuhr


Once you are either using distance_sphere or are using an appropriate
cartesian projection, you would then also want to add in order by
distance(...) asc at the end of your statement.  That way if you just want
the closest, you could also add limit 1 to the end of that.

David
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20060915/03e82ad3/attachment.html>


More information about the postgis-users mailing list