[postgis-users] How do I get 'n' points nearest another point?

Gerry Creager - NOAA Affiliate gerry.creager at noaa.gov
Mon Jun 22 16:05:47 PDT 2015


Thanks, all, for the suggestions. Brent, this is exactly what I needed!

gerry

On Mon, Jun 22, 2015 at 10:49 PM, Brent Wood <pcreso at pcreso.com> wrote:

> Hi Gerry,
>
> 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).
>
> select r.id from
> radar r,
> city c
> where c.id=<city point id>
> order by ST_Distance(c.point, r.point)
> limit 5;
>
> 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 r.id = c.id" to the
> where clause.
>
>
> Cheers
>
>   Brent Wood
>
>   ------------------------------
>  *From:* Gerry Creager - NOAA Affiliate <gerry.creager at noaa.gov>
> *To:* PostGIS Users Discussion <postgis-users at lists.osgeo.org>
> *Sent:* Tuesday, June 23, 2015 7:30 AM
> *Subject:* [postgis-users] How do I get 'n' points nearest another point?
>
> 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.
>
> I know I've done something similar, but that was 2 or 3 major releases
> ago, and the syntax is now foreign to me!
>
> Thanks in advance,
> 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)
>
> _______________________________________________
> postgis-users mailing list
> postgis-users at lists.osgeo.org
> http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-users
>
>


-- 
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)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20150622/a4145cee/attachment.html>


More information about the postgis-users mailing list