Book Image

PostGIS Cookbook

Book Image

PostGIS Cookbook

Overview of this book

Table of Contents (18 chapters)
PostGIS Cookbook
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Improving proximity filtering with KNN – advanced


In the preceding recipe, we wanted to answer the simple question of which are the nearest 10 locations to a given point, a simple question with a surprisingly sophisticated answer. Now that we have addressed the preceding question, the question is how do we approach this problem when we want to traverse an entire dataset and test each record for its nearest neighbors?

Our problem is as follows: for each point in our table, we are interested in the angle to the nearest object in another table. A case demonstrating this scenario is if we want to represent address points as building-like squares rotated to align with an adjacent road, similar to the historic United States Geological Survey (USGS) quadrangle maps, as shown in the following screenshot:

For larger buildings, USGS Quads show the buildings' footprints but, for residential buildings below their minimum threshold, the points are just rotated squares—a nice cartographic effect that could...