carbassot
carbassot

Reputation: 151

Find name of a street between 2 nodes. OSMnx

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?

Upvotes: 2

Views: 1458

Answers (1)

Sparky05
Sparky05

Reputation: 4892

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"].

Upvotes: 1

Related Questions