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? If I need to get at least this much exercise but don’t want to overdo it, how many kale shake joints are between 1K and 2K away from my home? How do I assign visits to my field reps to balance the work? 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 and PostGIS clustering window functions. Speed is often a concern when performing proximity analyses, and we’ll offer techniques and advice on how to speed up slow queries.