This chapter covers:
- Nearest neighbor searches
- K-Nearest Neighbor (KNN) distance operators
- Using KNN with geography and geometry
- Geotagging
Once you’ve located places with a set of coordinates, questions such as the following arise: How far is my house from the nearest expressway? How many burger joints are within a mile drive? What’s the average distance that people have to commute to work? Which three hospitals closest to me offer emergency vasectomies? We’ll file all these questions under the heading of proximity analysis, or loosely, the study of how far something is located from something else.
We’ll cover both the traditional methods of finding closest neighbors as well as newer methods using K-Nearest Neighbor (KNN) indexes. Speed is often a concern when performing proximity analyses, and we’ll offer techniques and advice on how to speed up slow queries.
We’ll also cover what you should consider when choosing between a geography
type and geometry
. We’ll discuss trade-offs such as performance, features, and ease of use.
We’ll end the chapter with geotagging. Geotagging is the labeling of spatial features, usually using data from another spatial feature, such as grouping locations into sales regions, finding all houses located along a street, and so on. Geotagging allows you to aggregate statistics more quickly and to export in formats that are friendly for spreadsheets and charts.