I used the OD Matrix to produce a list of the distances between all sites to all other sites via a network. This process produces duplicates, since it makes calculations in both directions, i.e., from Site 1 to Site 2 as well as from site 2 to site 1.

I tried to use the Vector general > delete duplicates by attribute tool to find these, but if one selects both ID and target, it deletes nothing, and if one selects the distance, it deletes others that are not duplicates.

I cannot import the matrix into Excel to edit (as I had planned to do) because the file is too large (2.14 million rows).

I want to reduce the result of OD Matrix down, by eliminating the duplicate rows (keeping (A, B) but deleting (B, A)).

Then I will want to filter the remaining rows by keeping only those under a certain threshold (11000), unless there are no lengths that short and taking the next shortest. I have been unable to find a solution for either of these in R or Python (but I don't yet know how to use either R or Python yet).

If the OD Matrix had more optional parameters it would help.

enter image description here


I have run it again, with a smaller set of sites and the results were the same.

I ran the OD Matrix both as Layer as Lines (m:n) and as Points to Lines (n:) and got the same result.

I used a road network of the Roman roads downloaded from Ancient World Mapping Center.

I am using a set of coordinates comprising 131 sites (with elevations), so there ought to be 8515 unique distances. I get 17161 as a result.

I can edit out the duplicates with R; but it is slightly annoying one cannot easily do it with the algorithm.

1 Answer 1


Avoiding duplicates

Creating duplicates should only be a problem if both origin- and destination layer are the same. For different layers, only connections from input to destination are calculated. As a workaround if you have the same layer: duplicate the layer and set the original as origin and the copy as destination.

Removing duplicates

If you already have the table with duplicates, you can remove the double entries using Menu Processing / Toolbox / Aggregate and use this expression to aggregate (collect, integrate) the duplicates to only one feature. Duplicates are based on the total cost (rounded here to 2 decimals as the values for one direction and inverse direction might not be 100% the same):

 round( "total_cost",2)

Set the aggregate function to "first value" to keep the values in the fields.

Screenshot: with 5 Points, OD-Matrix creates 5x5=25 connections. Running Aggregate reduces with the above expression reduces them to 11: the 10 you expect + one "self-connection" (from point 1 to point 1) containing value NULL (empty) or 0: enter image description here

  • I tried the method for removing duplicates, but it removed much more than the duplicates (I can't figure out how it worked, as only links from sites with numbers in 800s remained, number of features only 1465). So I tried re-running the matrix with a duplicate, but the results were the same as before (2,146,225 features). As I have 1465 sites, the correct number of rows ought to be 1,072,380.
    – jsilverman
    Commented Jul 13, 2021 at 7:49
  • Without having access to your project, it's difficult to say why it didn't work the same way as here. So at least a sample of your data would be helpful.
    – Babel
    Commented Jul 13, 2021 at 9:23
  • I have a dataset of 1465 sites, with coordinates and elevation, and a Roman road vector. They work perfectly well with the QNEAT3 closest path. I will add a screenshot above of the table of sites.
    – jsilverman
    Commented Jul 13, 2021 at 10:07
  • 1
    OK, so as long as I don't have access to the data, I can just speculate.
    – Babel
    Commented Jul 14, 2021 at 15:34
  • 1
    The round( "total_cost",2) appears to have worked; it produced 8500 lines.
    – jsilverman
    Commented Jul 15, 2021 at 12:12

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.