[postgis-users] Query all places within a given distance around a reference point

Per-Olof Norén pelle at alma.nu
Wed Dec 19 23:02:30 PST 2007


Hi,

Sebastien ARBOGAST skrev:
> It's the first time I play with a GIS database,
> and I need to perform some simple query. I could probably figure it
> out myself but the amount of documentation, specifications and
> standards to read is really frightening. So maybe someone can help me
> here.
>
> In my PostGIS database, I have a 'place' table whose
> 'location' column is a geometry (corresponding to a point).
> The inputs of my query are:
> - a reference POINT(lat,lon,alt) ref
> - a distance d
>
> Now I would like to write a query to find all the PLACE's
> whose location loc is such that the geodetic distance between ref and
> loc is less than a given distance d.
>
> How would I write such a query?
>
>   
Assuming you've read the docs:
http://postgis.refractions.net/docs/ch06.html

Something along the lines described below should work (havent tested myself)

select *
from place
where ST_distance_sphere(location, ST_MakePoint(lat,lon,alt)) < d

I'm quite sure the mail archives of postgis mailinglist has touched this 
subject as well.
http://postgis.refractions.net/pipermail/postgis-users/

Cheers,
Per-Olof







More information about the postgis-users mailing list