Use ORDER BY and LIMIT 4 to get the nearest 4 points:
Assuming your point table is called poi, and it has a 'geom' column, and a 'label' column, and "lon' and 'lat' give the coordinates of the starting location, then
SELECT poi.label, ST_Distance(poi.geom, MakePoint(lon, lat)) AS dist
FROM poi
ORDER BY dist ASC LIMIT 4;
 

On 22-May-14 11:47 PM, Gerry Creager - NOAA Affiliate wrote:
I need to query a rather smallish database and return 4 points closest to a lat/lon (or lon/lat, if you prefer) statement. I've been off-line from PostGIS and my skills are worse than rusty right now...

Thanks
Gerry
--
Gerry Creager
NSSL/CIMMS
405.325.6371
++++++++++++++++++++++
“Big whorls have little whorls,
That feed on their velocity; 
And little whorls have lesser whorls, 
And so on to viscosity.” 
Lewis Fry Richardson (1881-1953)

This mail was received via Mail-SeCure System.


_______________________________________________
postgis-users mailing list
[email protected]
http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-users
This mail was received via Mail-SeCure System.



-- 
Moshav Idan
D.N. Arava, 86840
cell: 0523-665918
http://www.surfaces.co.il
_______________________________________________
postgis-users mailing list
[email protected]
http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-users

Reply via email to