Skip site navigation (1) Skip section navigation (2)

Re: nearest neighbor search from xyz coordinates

From: Angel Alvarez <clist(at)uah(dot)es>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: nearest neighbor search from xyz coordinates
Date: 2008-10-27 19:45:20
Message-ID: 200810272045.21709.clist@uah.es (view raw or flat)
Thread:
Lists: pgsql-general
El Lunes 27 Octubre 2008 Andreas Jochem escribió:
> Hello,
> 
> I have a table containing x y z coordinates. But I have no geometry column?
> Is it possible to find the k nearest neighbors of any point. Is there 
> something like a kd-tree Index in postgres???
> 
> I know, if i had a geometry column I could make use of the distance 
> function to find the k nearest neighbors. But my table has millions of 
> records, thus it would take a very long time to use the distance 
> function for each point.
> 
> Thanks in advance.
> 
> Andi
> 
Maybe you can partition your 3d space into cubes and add one colum to the table precalculating the cube
that owns the point.

For an arbitrary point you can calculate the cube that contains it and surrounding boxes and 
restrict full distance calculation to records belonging to those cubes. 

for millions of points seems to be faster than trying all points blindy (despite of being indexed).


-- 

->>-----------------------------------------------
    Clist UAH a.k.a Angel
---------------------------------[www.uah.es]-<<--
""

In response to

pgsql-general by date

Next:From: Tom LaneDate: 2008-10-27 19:51:57
Subject: Re: PostgreSQL 8.3.3 chooses wrong query plan when LIMIT 1 added?
Previous:From: Simon RiggsDate: 2008-10-27 19:24:29
Subject: Re: PostgreSQL 8.3.3 chooses wrong query plan when LIMIT1 added?

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group