How can I convert an OSM XML file into a graph representation (such that ways become edges of the graph and intersections/junctions become the nodes of the graph)? asked 19 Jan '13, 16:56 Sadeer aseerel4c26 ♦ 
Assuming you want only roads, then a possible algorithm is this:
If you are only working on a small data set you can of course simply read everything into memory and do the above analysis in memory. answered 19 Jan '13, 17:17 Frederik Ramm ♦ "throw away those that are not roads" the devil is in the details. You can't search for ways tagged with car=yes. So if you need a graph for only cars you will probably need to look at filters used by available routers.
(21 Jan '13, 11:19)
emj
@emj: Correct. You should search for ways with highway tag other than pedestrian,footway,cycleway,bridleway. And eliminate oneways with final point unconnected.
(03 May '13, 12:28)
erkinalp
Hi,i am wondering why exactly we need to execute step #2 from above? The logic is mainly implemented in the python script here : https://gist.github.com/aflaxman/287370 So if I remove lines 144159 from the script in the link (i.e. omit the step #2 from above) I get a fine graph as well.
(02 Jul '15, 16:21)
rajanskus
1
Depends on your definition of "graph". Usually, a graph consists of nodes and edges, where each edge connects to exactly two nodes. If you leave out step 2, you will end up with something where an edge can go from node A across node B to node C. This is not a graph, and various graphbased routing engines or network analyzers will have trouble working with that.
(09 Jul '15, 18:11)
Frederik Ramm ♦
Hi, one short question...what do you exactly mean with "link counter"?
(10 Jul '15, 06:33)
madalina_ias...
link counter := number of ways by which one node is used.
(24 Jul '15, 21:09)
Frederik Ramm ♦
Link counter means degree of the vertex.
(22 Feb '16, 10:45)
Ankita_Mehta
showing 5 of 7
show 2 more comments

Working with OSM and Java implementation using Jgrapht library http://www.sandeepsas.com/howdoistartworkingwithopenstreetmaposm/ answered 27 Feb '16, 22:39 Sandeep40 
This blog post by the author of OSRM might be helpful.