0

I am looking to be able able to link the Vertex ID with the coordinate positions.

Using m.edge_matrix I can generate the list of vertex IDs for the edges that form a polyline. What is the easiest way to link this back to the actual coordinates?

Using m.vertex_matrix produces the list of coordinates, but has no reference to the Vertex ID. The order in which the coordinates are listed in m.vertex_matrix doesn't appear to link to the order in which they appear in m.edge_matrix

Many thanks.

1 Answers1

1

The matrix returned by m.vertex_matrix() is indexable. The row n corresponds to coordinates of vertex with id=n, so you just need to use [ ] to read the row.

v = m.vertex_matrix()
for e in m.edge_matrix():
  print("edge", e, "goes from", v[e[0]], "to", v[e[1]])

which produces this output:

edge [0 1] goes from [0.12843863 0.38690682 0.1] to [0.13383933 0.3839188  0.1]
edge [2 3] goes from [0.14307424 0.38100217 0.1] to [0.13592989 0.38318165 0.1]
edge [3 1] goes from [0.13592989 0.38318165 0.1] to [0.13383933 0.3839188  0.1]
edge [4 5] goes from [0.25161905 0.21663008 0.1] to [0.2520413  0.21464215 0.1]
edge [6 5] goes from [0.25537567 0.20097797 0.1] to [0.2520413  0.21464215 0.1]
Rockcat
  • 3,002
  • 2
  • 14
  • 28