Matrix: reduce results to e.g. shortest distance

I’m using the ORS Tools plugin for QGIS where I wanted to calculate the closest by school (out of 4 in total) for students in a certain municipality.

The matrix-tool in the plugin generates for each student 4 separate records in which the distance (and time) to each school is calculated. So, the resulting matrix contains in my case: number of students x 4 (number of schools).

It would be useful if the plugin would have the possibility to keep only, for example, the shortest distance, so that the number of records in the resulting matrix is equal to the number of students and only the closest by school (with duration and distance) is shown.

If adding this option into the plugin would not be possible, but I could do it in QGIS in some way or another (e.g. by creating a virtual layer using the resulting matrix), this would also be fine for me.

Hey,

this is a question of data processing afterwards, and not a problem that the QGIS plugin will solve.

I’m assuming this is possible in QGIS, but wouldn’t know how to do it from the top of my head.
For help regarding this, please refer to QGIS help channels (see this list).

Best regards

1 Like

I indeed found a quick way to do it with a virtual layer in QGIS:
SELECT FROM_ID, TO_ID, DURATION_H, MIN(DIST_KM)
FROM tablename
GROUP BY FROM_ID

I asked the question because in the tool Matrix_calculation in QGIS (where you can calculate the lineair (not over a network) distance between an input point layer and a destination point layer), you actually can select a setting to retain only the shortest destination point. It would be useful if such a similar setting would be integrated in the Matrix-tool of the ORS Plugin.

Hey,

if this is a feature that you’d like to see integrated into the QGIS plugin, you can open a feature request in our repository.

I assume that this feature exists because it reduces calculation time, especially on large data sets.
Note, however, that this would not happen in the QGIS plugin, since first the complete matrix would have to be calculated and then it would have to get “truncated” to the desired output.

Since it seems to be rather easy to calculate the desired result from the matrix output, I don’t think this will get added anytime soon.

Best regards

1 Like

This is the issue Add preference selection to matrix to allow 'shortest' distance & duration · Issue #1178 · GIScience/openrouteservice · GitHub