# How do I calculate proximity for multiple points?

I have two layers, one with lots, one with subway stations (NYC). There are to scenarios:

Case 1. I want to rank the lots relative to the proximity to subways.

(1.a.) The closer to closest station, the better or
(1.b.) The closer to multiple stations, the better.

Case 2. I want to evaluate the area surrounding the lots, say 500m radius. I would calculate the distance from the center of each block to the nearest subway station(s). For each block, the distance will be multiplied by the number of residents. Then the sum of those values will be divided by the total population in the area.

How can I do this in QGIS or/and PostGis?

• Here is a nice tutorial on using Nearest Neighbors in QGIS. qgistutorials.com/en/docs/nearest_neighbor_analysis.html
– GBG
Commented Nov 8, 2018 at 20:49
• 1.a/b) in PostGIS: get (K) Nearest Neighbors to each block and their distances via KNN search with, say, `k=10`; get ID of closest (1.a), and rank over the bottom percentile of accumulated distances (1.b). you can solve 2) with the same set. Commented Nov 9, 2018 at 8:36

Use the `distance to nearest hub` tool to calculate the distance from each lot to the closest station. This tool requires points as input, so if your lots are polygons, use the `centroids` or `points on surface` tool to turn them into points.
Install the refFunctions plugin, and use the `intersecting_geom_count()` function in the Field Calculator to count the number of stations within each buffer and add that as a new attribute. Join the buffer layer back to the original point layer to get the station count as an attribute of the point layer.