X-Original-To: pgsql-advocacy-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 8760C534F5; Mon, 28 Mar 2005 18:23:21 +0100 (BST) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 15589-08; Mon, 28 Mar 2005 17:23:17 +0000 (GMT) Received: from joeconway.com (wsip-24-249-201-67.sd.sd.cox.net [24.249.201.67]) by svr1.postgresql.org (Postfix) with ESMTP id 294015348C; Mon, 28 Mar 2005 18:23:16 +0100 (BST) Received: from [206.19.64.3] (account jconway HELO [172.16.1.115]) by joeconway.com (CommuniGate Pro SMTP 4.1.8) with ESMTP-TLS id 2718980; Mon, 28 Mar 2005 10:22:47 -0800 Message-ID: <42483D83.4030209@joeconway.com> Date: Mon, 28 Mar 2005 09:23:15 -0800 From: Joe Conway User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.7.6) Gecko/20050323 Fedora/1.7.6-1.3.2 X-Accept-Language: en-us, en MIME-Version: 1.0 To: Bruno Wolff III Cc: Virgile Beddok , Tom Lane , Christopher Kings-Lynne , pgsql-novice@postgresql.org, pgsql-advocacy@postgresql.org Subject: Re: [NOVICE] Function which gives back the nearest References: <2657.146.140.8.144.1111775776.squirrel@webmail.igd.fraunhofer.de> <42464392.9040903@familyhealth.com.au> <20050327163653.GH9280@wolff.to> <5796.1111941132@sss.pgh.pa.us> <1218.146.140.8.94.1112025141.squirrel@webmail.igd.fraunhofer.de> <20050328161240.GD7217@wolff.to> <1343.146.140.8.94.1112027529.squirrel@webmail.igd.fraunhofer.de> <20050328172223.GA11567@wolff.to> In-Reply-To: <20050328172223.GA11567@wolff.to> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.047 tagged_above=0 required=5 tests=AWL, FORGED_RCVD_HELO X-Spam-Level: X-Archive-Number: 200503/124 X-Sequence-Number: 6552 Bruno Wolff III wrote: > On Mon, Mar 28, 2005 at 18:32:09 +0200, > Virgile Beddok wrote: > >>I just want to know if there is an existing and implemented function, or >>tree, in Postgres which allows me to directly perform a "nearest neighbour >>search" on multidimensional vectors. > > > How are you measuring distance? (i.e. Euclidean distance isn't the only > metric that you could be using.) > > Earthdistance has functions for doing this using geodesics on the surface > of a sphere. > > For 2D, I think there is a function on "point"s that uses Euclidean > distance. > > I don't think this is the hard part of your problem. It is easy to create > a metric function and get the point corresponding to the minimal value > using a sort. Being able to limit the sets of points looked at is the > hard part. You might want to look into using R: http://www.bioconductor.org/CRAN/ (see "Packages") perhaps through PL/R: http://www.joeconway.com/plr/ or RdbiPgSQL: http://www.bioconductor.org/repository/release1.5/package/html/RdbiPgSQL.html Joe