[postgis-users] reverse geocoding

Kevin Neufeld kneufeld at refractions.net
Mon Mar 29 22:41:03 PDT 2010


On 3/29/2010 9:58 PM, Stephen Woodbridge wrote:
> If you have a POINT then you can find the closest centerline within 
> some RADIUS with:
>
> select *, distance(POINT, the_geom) as dist
>   from lines
>  where expand(POINT, RADIUS) && the_geom
>  order by dist limit 1;
>
> -Steve

Or to find the closest centerline for all points in your point table:

SELECT DISTINCT ON (a.gid) a.*, b.*, ST_Distance(a.geom, b.geom) AS dist
FROM points a, lines b
WHERE ST_Expand(a.geom, RADIUS) && b.geom
ORDER BY a.gid, dist ASC;

Cheers,
Kevin



More information about the postgis-users mailing list