I hope to calculate the distance between each property in the Washington DC metropolitan area and the nearest metro station, and I am doing this for each month from 2000 to 2017. I use Distance Matrix in QGIS 3, set the property layer as the Input Layer and the metro stations layer as the Target Layer, and use only the nearest 1 target point. From 2000 to 2017, several new metro stations opened in the DC metropolitan area while no station was closed.

The results are mostly fine. Most properties have the same closest metro stations throughout the period and the distances remain the same. Some properties have different closest metro stations as time goes on due to introduction of new stations, and the distances fall as new stations open.

However, after opening of new stations, some small portion of properties (although still large number in absolute terms) are each mapped to a new station that is farther away then the station mapped to it before new stations open. For example, McLean Station of Silver Line opened in July 2014. For a bunch of properties in my data, QGIS identifies Rockville Station of Red Line as their closest metro station before July 2014. After July 2014, QGIS identifies McLean Station as their closest station, but the distances between these properties and McLean Station are larger than the distances between them and Rockville Station.

I manually checked for around 20-30 of such cases and find no error in the distances calculated by QGIS but why does QGIS not map these properties to Rockville Station which is still the closest station even after the opening of McLean Station?


1 Answer 1


The Distance matrix algorithm currently uses a Cartesian spatial filter based on the CRS of the target layer to find the k nearest points, and calculates the ellipsoidal distance for only those points. [Distance Matrix returns wrong record/result when using Linear Distance Matrix with k=1]

This is generally problematic. And it is especially problematic when k=1 (the closest point in planar coordinates is not necessarily the closest on the ellipsoid surface) and even more so when the CRS of the target layer is geographic (the spatial filter assumes the geographic coordinates as if were flat).

Therefore, if your intention is to find the closest point on the ellipsoid surface, be sure to reproject the layers to a CRS that doesn't distort distances too much in your area of work, let the filter loosely calculate the distances to several of the nearest points, and end up choosing the closest one based on the resulting values in the Distance field.

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.