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.
    – geozelot
    Commented Nov 9, 2018 at 8:36

1 Answer 1


For case 1a, "The closer to closest station, the better"

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.

For case 1b, "The closer to multiple stations, the better"

Decide on an acceptable distance radius, so you can count, eg number of stations within a 500m radius. Buffer the points by that radius.

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.

For case 2, you can use the answer to case 1b as a starting point, but this should be posted as a separate question, per the "one question per question" guideline. See guidelines here: Asking good Questions for GIS Stack Exchange?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.