[postgis-users] Distance between points

Stephen Woodbridge woodbri at swoodbridge.com
Sun Aug 28 22:16:33 PDT 2011


select id, distance_sphere(setsrid(makepoint(-71.112678, 42.331002), 
4326), setsrid(makepoint(longitude, latitude), 4326)) as dist_meters 
from places;

If you are looking for great circle distances the maybe using geography 
instead of geometry type would work better.

-Steve W

On 8/28/2011 1:22 PM, Marcelo Pereira wrote:
> Hello Everybody,
>
> I have got a very simple question about distance between two points:
>
> I have the following table:
>
>     CREATE TABLE places (
>         id   SERIAL,
>         latitude  DOUBLE PRECISION,
>         longitude DOUBLE PRECISION
>     );
>
>
> with the following content:
>
> geo=# SELECT * FROM places;
>   id | latitude  | longitude
> ----+-----------+------------
>    1 | 42.331002 |  -71.112678
>    2 | 42.335158 |  -71.102464
>    3 | 33.911400 | -116.768000
>    4 | 40.415748 |   -3.707135
>    5 | 35.684750 |  139.751158
> (5 rows)
>
> I would like to know the distance between "one fixed point" (42.331002
> -71.112678) and all points in this table.
>
> Simple like this!! Could someone help me?
>
> For now, I don't need to considere zones!! I just need to compare "one
> point" against all points in the table!!
>
> Thanks in advance,
> Marcelo
>
>
> _______________________________________________
> postgis-users mailing list
> postgis-users at postgis.refractions.net
> http://postgis.refractions.net/mailman/listinfo/postgis-users




More information about the postgis-users mailing list