<div dir="ltr">I'll try this after putting out a few new fires! mylat and mylon are WKT? <div><br></div><div>Thanks!<div>gerry</div></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, May 23, 2014 at 8:54 AM, Stephen Woodbridge <span dir="ltr"><<a href="mailto:woodbri@swoodbridge.com" target="_blank">woodbri@swoodbridge.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">SELECT poi.label, ST_Distance(MakePoint(lon, lat), MakePoint(mylon, mylat)) AS dist<div class=""><br>
     FROM poi<br>
     ORDER BY dist ASC LIMIT 4;<br>
<br></div>
-- or --<br>
<br>
SELECT poi.label, ST_Distance(geom, MakePoint(mylon, mylat)) AS dist<div class=""><br>
     FROM poi<br>
     ORDER BY dist ASC LIMIT 4;<br>
<br></div>
where mylon, and mylat are you arbitray point locations.<br>
<br>
-Steve<div class=""><br>
<br>
On 5/23/2014 9:46 AM, Gerry Creager - NOAA Affiliate wrote:<br>
</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="">
The inherent problem is that the point will be arbitrarily specified. I<br>
need to find the 4 points in the table 'sites' (it has label, geom, and<br>
lat, lon columns) closest to an arbitrary point given a lat/lon<br>
coordinate pair.<br>
<br>
Or, am I making this harder than I think I am?<br>
<br>
Thanks!<br>
gerry<br>
<br>
<br>
On Fri, May 23, 2014 at 5:49 AM, Micha Silver <<a href="mailto:micha@arava.co.il" target="_blank">micha@arava.co.il</a><br></div><div class="">
<mailto:<a href="mailto:micha@arava.co.il" target="_blank">micha@arava.co.il</a>>> wrote:<br>
<br>
    Use ORDER BY and LIMIT 4 to get the nearest 4 points:<br>
    Assuming your point table is called poi, and it has a 'geom' column,<br>
    and a 'label' column, and "lon' and 'lat' give the coordinates of<br>
    the starting location, then<br>
    SELECT poi.label, ST_Distance(poi.geom, MakePoint(lon, lat)) AS dist<br>
    FROM poi<br>
    ORDER BY dist ASC LIMIT 4;<br>
<br>
<br>
<br>
    On 22-May-14 11:47 PM, Gerry Creager - NOAA Affiliate wrote:<br>
</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="">
    I need to query a rather smallish database and return 4 points<br>
    closest to a lat/lon (or lon/lat, if you prefer) statement. I've<br>
    been off-line from PostGIS and my skills are worse than rusty<br>
    right now...<br>
<br>
    Thanks<br>
    Gerry<br>
    --<br>
    Gerry Creager<br>
    NSSL/CIMMS<br></div>
    <a href="tel:405.325.6371" value="+14053256371" target="_blank">405.325.6371</a> <tel:<a href="tel:405.325.6371" value="+14053256371" target="_blank">405.325.6371</a>><div class=""><br>
    ++++++++++++++++++++++<br>
    “Big whorls have little whorls,<br>
    That feed on their velocity;<br>
    And little whorls have lesser whorls,<br>
    And so on to viscosity.”<br>
    Lewis Fry Richardson (1881-1953)<br>
<br>
    This mail was received via Mail-SeCure System.<br>
<br>
<br>
    ______________________________<u></u>_________________<br>
    postgis-users mailing list<br></div>
    <a href="mailto:postgis-users@lists.osgeo.org" target="_blank">postgis-users@lists.osgeo.org</a>  <mailto:<a href="mailto:postgis-users@lists.osgeo.org" target="_blank">postgis-users@lists.<u></u>osgeo.org</a>><div class="">
<br>
    <a href="http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-users" target="_blank">http://lists.osgeo.org/cgi-<u></u>bin/mailman/listinfo/postgis-<u></u>users</a><br>
    This mail was received via Mail-SeCure System.<br>
<br>
<br>
</div></blockquote><div class="">
<br>
    --<br>
    Moshav Idan<br>
    D.N. Arava, 86840<br>
    cell: 0523-665918<br>
    <a href="http://www.surfaces.co.il" target="_blank">http://www.surfaces.co.il</a><br>
<br>
<br>
    ______________________________<u></u>_________________<br>
    postgis-users mailing list<br></div>
    <a href="mailto:postgis-users@lists.osgeo.org" target="_blank">postgis-users@lists.osgeo.org</a> <mailto:<a href="mailto:postgis-users@lists.osgeo.org" target="_blank">postgis-users@lists.<u></u>osgeo.org</a>><div class="">
<br>
    <a href="http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-users" target="_blank">http://lists.osgeo.org/cgi-<u></u>bin/mailman/listinfo/postgis-<u></u>users</a><br>
<br>
<br>
<br>
<br>
--<br>
Gerry Creager<br>
NSSL/CIMMS<br>
<a href="tel:405.325.6371" value="+14053256371" target="_blank">405.325.6371</a><br>
++++++++++++++++++++++<br>
“Big whorls have little whorls,<br>
That feed on their velocity;<br>
And little whorls have lesser whorls,<br>
And so on to viscosity.”<br>
Lewis Fry Richardson (1881-1953)<br>
<br>
<br></div><div class="">
______________________________<u></u>_________________<br>
postgis-users mailing list<br>
<a href="mailto:postgis-users@lists.osgeo.org" target="_blank">postgis-users@lists.osgeo.org</a><br>
<a href="http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-users" target="_blank">http://lists.osgeo.org/cgi-<u></u>bin/mailman/listinfo/postgis-<u></u>users</a><br>
<br>
</div></blockquote><div class="HOEnZb"><div class="h5">
<br>
______________________________<u></u>_________________<br>
postgis-users mailing list<br>
<a href="mailto:postgis-users@lists.osgeo.org" target="_blank">postgis-users@lists.osgeo.org</a><br>
<a href="http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-users" target="_blank">http://lists.osgeo.org/cgi-<u></u>bin/mailman/listinfo/postgis-<u></u>users</a><br>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br><div dir="ltr">Gerry Creager<div>NSSL/CIMMS</div><div>405.325.6371</div><div>++++++++++++++++++++++</div><div><div>“Big whorls have little whorls,</div>
<div>That feed on their velocity; </div><div>And little whorls have lesser whorls, </div><div>And so on to viscosity.” </div><div>Lewis Fry Richardson (1881-1953)</div></div></div>
</div>