I have shapefile that looks like this: I need to make a matrix (or just to add a couple of fields in the attribute table, something like the origin-destination matrix), which will have the number of links that go from each point to target point. I mean, I don't have physically point, just beginning and end of each line. For example, matrix/attribute table should look like this:

Target_point_coord     Point_coord_1    Point_coord_2  ...   Point_coord_N
  point_coord_1              0            15           ...     50
  point_coord_2             15             0           ...     2
  point_coord_N             50             2                   0

this means that 15 lines from point 2 go to point 1, 50 lines from point N to point 1, etc. Or to be more clear, this also means that 15 lines have started at point_coordinates_2 and ended at target_point_1, and so on. The lines are not directed so that I have for the row 2 that 15 lines from point_coord_1 go to Point_coord_2.

I approximately have about 150 points and I also have the list of that points in the CSV file, if it's matter.

Is there is a way to do this in QGIS or PyQGIS? And if it is, how?

  • Is your data a single layer of line geometry class where each element is exactly one line segment? What is the tolerance for two points to be the same point entity? – Spacedman Mar 11 at 8:08
  • Some of the lines have more than one segment, but I need to look just from the last point to the next one. I can solve that with dissolving (turning all multilines in more single lines). I have around 150 points and each line finishes/starting in one of exactly these points. I know that for sure because this shapefile was created from that intersection points. I have also the list of coordinates of that points in CSV file. – Neven Mar 11 at 8:42

This in not direct solution, but some workaround.

1) With Extract vertices (from processing) You will get all vertices from the all the lines with all the data and also index of points along the line.

enter image description here


2) With Extract specific vertices when only the start and end is important, you can extract vertices 0 (start point) and -1, (end point)

enter image description here

After that make some join by location action, to get desired output. And in final step, use Points to path to convert points to new lines.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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