Re: Finding points within 50 miles
От
Janning Vygen
Тема
Re: Finding points within 50 miles
Дата
Msg-id
200506270947.36633.vygen@gmx.de
Ответ на
Список
Дерево обсуждения
Finding points within 50 miles CSN <cool_screen_name90001@yahoo.com>
Re: Finding points within 50 miles "Uwe C. Schroeder" <uwe@oss4u.com>
Re: Finding points within 50 miles Alban Hertroys <alban@magproductions.nl>
Re: Finding points within 50 miles "Uwe C. Schroeder" <uwe@oss4u.com>
Re: Finding points within 50 miles John Browne <jkbrowne@gmail.com>
Re: Finding points within 50 miles Vivek Khera <vivek@khera.org>
Re: Finding points within 50 miles Bruno Wolff III <bruno@wolff.to>
Re: Finding points within 50 miles Vivek Khera <vivek@khera.org>
Re: Finding points within 50 miles Janning Vygen <vygen@gmx.de>
Re: Finding points within 50 miles Vivek Khera <vivek@khera.org>
Re: Finding points within 50 miles Oleg Bartunov <oleg@sai.msu.su>
Re: Finding points within 50 miles Bruno Wolff III <bruno@wolff.to>
Re: Finding points within 50 miles Vivek Khera <vivek@khera.org>
Am Montag, 27. Juni 2005 01:40 schrieb CSN:
> If I have a table of items with latitude and longitude
> coordinates, is it possible to find all other items
> that are within, say, 50 miles of an item, using the
> geometric functions
> (http://www.postgresql.org/docs/8.0/interactive/functions-geometry.html)?
> If so, how?
I did it without some special features and datatypes some time ago. feel free
to modify and use for your own. It should give you an idea how to do it.
SELECT
c1.zip,
c2.zip,
6378.388 *
acos(
sin(radians(c1.latitude)) * sin(radians(c2.latitude))
+ cos(radians(c1.latitude)) * cos(radians(c2.latitude))
* cos(radians(c1.longitude - c2.longitude))
) AS distance
FROM
coordinates AS c1
CROSS JOIN coordinates AS c2
I had some problems with the calculation inside acos() sometimes being greater
than 1, which should not occur. Please use a
CASE WHEN sin(...) > 1 THEN 1 ELSE sin(...) END
if you have the same problem.
kind regards,
janning
В списке pgsql-general по дате отправления