Re: Finding points within 50 miles

From: Oleg Bartunov <oleg(at)sai(dot)msu(dot)su>
To: Janning Vygen <vygen(at)gmx(dot)de>
Cc: pgsql-general(at)postgresql(dot)org, CSN <cool_screen_name90001(at)yahoo(dot)com>
Subject: Re: Finding points within 50 miles
Date: 2005-06-27 08:46:17
Message-ID: Pine.GSO.4.63.0506271244050.26882@ra.sai.msu.su
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

How big is your data ? There are rather sophisticated and
very effective methods in astronomy. For example,
http://www.sai.msu.su/~megera/oddmuse/index.cgi/SkyPixelization,
http://www.sai.msu.su/~megera/oddmuse/index.cgi/pg_sphere

Oleg
On Mon, 27 Jun 2005, Janning Vygen wrote:

> 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
>
> ---------------------------(end of broadcast)---------------------------
> TIP 5: Have you checked our extensive FAQ?
>
> http://www.postgresql.org/docs/faq
>

Regards,
Oleg
_____________________________________________________________
Oleg Bartunov, sci.researcher, hostmaster of AstroNet,
Sternberg Astronomical Institute, Moscow University (Russia)
Internet: oleg(at)sai(dot)msu(dot)su, http://www.sai.msu.su/~megera/
phone: +007(095)939-16-83, +007(095)939-23-83

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Alban Hertroys 2005-06-27 09:08:35 Re: Finding points within 50 miles
Previous Message Ulrich Wisser 2005-06-27 08:37:46 vacuum error