2

I want to find the name of the street between 2 nodes. I did some research and with Networkx I think it is possible. Following this question's answer: OSMNx : get coordinates of nodes using OSM id

I can see that finding for example, some node's coordinates I just have to write G.nodes[id]['x]. However I try to find the name between 2 streets like this: (Assuming G is my graph)

G.nodes[id_src][id_dst]['name']

And it returns this error:

KeyError: 667410900

I assume this number is the node's ID.

How can I get the street name?

carbassot
  • 141
  • 1
  • 10

1 Answers1

1

Under the assumption that your graph is build in the way that crossings/dead ends are the nodes and the streets are the edges in your graph. You can access the street informations via (see documentation)

G.edges[(id_src, id_dst)]["name"]
# or display all data, with all possible names
print(G.edges[(id_src, id_dst)])

In the case of OSMNx you work with an MultiDiGraph you need to specify which edge you want, i.e.,

G.edges[(id_src, id_dst, 0)]["name"]
# or
G.edges[(id_src, id_dst, 0)]["length"].
Sparky05
  • 4,692
  • 1
  • 10
  • 27
  • In case I want to find the lenght of an edge, should I do the same replacinc "name" by "lenght"? – carbassot May 13 '20 at 12:12
  • 1
    Yes that should work. I've extended my answer to include that case as well. – Sparky05 May 13 '20 at 12:15
  • Is there any chance this or something similar could work to find the angle between nodes? – carbassot May 17 '20 at 19:12
  • 1
    Probably you can approximate the angle from the longitude and latitude of the different crossings. Alternatively, you can check which information is available in the OSMNx model, either directly incorporated for the nodes or the edges, or even only available via a method call. I would recommend to open a new question, if you can't solve it by yourself. – Sparky05 May 18 '20 at 11:35