[SciPy-User] 2D NN search in a 3D point cloud

Bastian Weber bastian.weber@gmx-topmail...
Thu Sep 22 11:10:30 CDT 2011

On 09/22/2011 02:13 PM, Andrej Kobler wrote:
> Hi,
> in a cloud of XYZ points I’d like to search for nearest neighbors in XY
> plane using scipy.spatial.KDTree/cKDTree. The problem is that
> KDTree.query takes into account all the given dimensions, not just the
> desired subset of dimensions. Is there a simple way to have data with 3
> or more dimensions and use only 2 for NN search?

Probably I dont have enough insight but I simply would try to neglect 
the last coordinate of the data.

Assuming you have points_xyz.shape == (N,3) where N is the number of 
points then you could simply do:

points_xy = points_xyz[:,:2].

Applying the NN search on this data should give you the desired result.

Best regards,


More information about the SciPy-User mailing list