<div dir="ltr">Thanks, all, for the suggestions. Brent, this is exactly what I needed!<div><br></div><div>gerry</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Jun 22, 2015 at 10:49 PM, Brent Wood <span dir="ltr"><<a href="mailto:pcreso@pcreso.com" target="_blank">pcreso@pcreso.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div style="color:#000;background-color:#fff;font-family:HelveticaNeue,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif;font-size:16px"><div><span>Hi Gerry,<br></span></div><div><span><br></span></div><div><span>Not optimised but essentially get your city point, get the distances to each of the radar points, sort on distance, return the first n (5).<br></span></div><div><span><br></span></div><div><span>select <a href="http://r.id" target="_blank">r.id</a> from</span></div><div dir="ltr"><span>radar r,</span></div><div dir="ltr"><span>city c</span></div><div dir="ltr"><span>where <a href="http://c.id" target="_blank">c.id</a>=<city point id><br></span></div><div dir="ltr"><span>order by ST_Distance(c.point, r.point)</span></div><div dir="ltr"><span>limit 5;</span></div><div><br></div><div>Any way you can reduce the number of radar points to test the distance for will improve performance - like if the radar table has a city id column you can restrict the search to just those by adding "and <a href="http://r.id" target="_blank">r.id</a> = <a href="http://c.id" target="_blank">c.id</a>" to the where clause. <br></div><div><br></div><div><br></div><div>Cheers</div><div><br></div><div dir="ltr">  Brent Wood<br></div><div><br>  </div><div style="font-family:HelveticaNeue,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif;font-size:16px"> <div style="font-family:HelveticaNeue,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif;font-size:16px"> <div dir="ltr"> <hr size="1">  <font face="Arial" size="2"> <b><span style="font-weight:bold">From:</span></b> Gerry Creager - NOAA Affiliate <<a href="mailto:gerry.creager@noaa.gov" target="_blank">gerry.creager@noaa.gov</a>><br> <b><span style="font-weight:bold">To:</span></b> PostGIS Users Discussion <<a href="mailto:postgis-users@lists.osgeo.org" target="_blank">postgis-users@lists.osgeo.org</a>> <br> <b><span style="font-weight:bold">Sent:</span></b> Tuesday, June 23, 2015 7:30 AM<br> <b><span style="font-weight:bold">Subject:</span></b> [postgis-users] How do I get 'n' points nearest another point?<br> </font> </div> <div><div><div class="h5"><br><div><div dir="ltr">I've two tables, one with a set of city centroids, and one with radar locations. I need to select the 4 (or maybe 5) closes radars to a given city point. <div><br></div><div>I know I've done something similar, but that was 2 or 3 major releases ago, and the syntax is now foreign to me!</div><div><br></div><div>Thanks in advance,<br clear="all"><div>gerry</div>-- <br><div><div dir="ltr">Gerry Creager<div>NSSL/CIMMS</div><div><a href="tel:405.325.6371" value="+14053256371" target="_blank">405.325.6371</a></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>
</div></div></div><br></div></div>_______________________________________________<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-bin/mailman/listinfo/postgis-users</a><br><br></div> </div> </div>  </div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature"><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>
</div>