9 Proximity analysis

 

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.

9.1  Nearest neighbor searches

 
 
 

9.1.1  Which places are within X distance?

 
 
 

9.1.2  Using ST_DWithin and ST_Distance for N closest results

 
 
 

Using ST_DWithin and DISTINCT ON to find closest locations

 
 
 

9.1.3  Intersects with tolerance

 
 
 
 

9.1.4  Finding N closest places using KNN distance operators

 
 
 

9.2  Using KNN with geography types

 
 
 

9.2.1  Using window functions to number closest N places

 
 
 

9.3  Geotagging

 
 
 

9.3.1  Tagging data to a specific region

 
 
 

9.3.2  Linear referencing: snapping points to the closest linestring

 

9.4  Summary

 
 
 
 
sitemap

Unable to load book!

The book could not be loaded.

(try again in a couple of minutes)

manning.com homepage
test yourself with a liveTest