Contents
kNN (k Nearest-Neighbour)
A type of spatial query
kNN
(k Nearest-Neighbour
) is a type of spatial query for searching the closest neigbours to an object, regardless of distance.
PostgreSQL support
btree_gist
- the
btree_gist
extension provideskNN
support from PostgreSQL 9.1
- the
cube
- the
cube
extension provideskNN
support from PostgreSQL 9.6
- the
PostGIS
- from version 2.2.0 / PostgreSQL 9.5 provides true
kNN
behaviour for geometry and geography via the<->
operator (see the PostGIS <-> documentation)
- from version 2.2.0 / PostgreSQL 9.5 provides true
SP-GiST
- SP-GiST indexes support
kNN
searches from PostgreSQL 12
- SP-GiST indexes support
Useful links
- Introduction to PostGIS: Nearest-Neighbour Searching - PostGIS tutorial
- Won’t You Be My Neighbor? Quickly Finding Who is Nearby - October 2018 blog article by Crunchy Data
- PostgreSQL 12: Implementing K-Nearest Neighbor Space Partitioned Generalized Search Tree Indexes - November 2019 blog article by 2ndQuadrant