Answers to: How to calculate street length from osm data?https://help.openstreetmap.org/questions/45705/how-to-calculate-street-length-from-osm-data<p>Hello people!</p>
<p>I am new to OSM so I am sorry if my question seems stupid to someone. Currently I am doing a Java project using real world map data, so naturally OSM was my choice to obtain the data.</p>
<p>The idea of the project is simple - osm data (in my case in json format) is parsed and loaded into the java and from there I build a weighted directed graph to represent the whole map. All calculations that I need to do are done on the graph. So far i've made a simple module to parse the nodes and ways from the OSM json file thus I have the nodes and the edges of my graph.
The problem is that OSM data did not have any info on the length of the ways/streets. I need that information because this is going to be the weights on my graph.</p>
<p>I tried using JOSM, it had a measurement tool which gave me the lengths of the road segments but I have absolutely no idea how it works. </p>
<p>Is there a way to obtain this kind of data? Are there any other services on the internet that provide real world map data but with lengths of street segments included?</p>
<p>Thanks for you help! If you have any clarifying questions I will gladly answer! </p>enSun, 04 Oct 2015 21:21:29 +0100Answer by aseerel4c26https://help.openstreetmap.org/questions/45705/how-to-calculate-street-length-from-osm-data/45706<p>Each <a href="https://wiki.openstreetmap.org/wiki/Elements">node</a> has a real-world coordinate. To get the length of a way, calculate the distance based on the coordinates of its nodes (WGS84 projection). A popular formula for these calculations is the Haversine formula, and you'll find example implementations for many programming languages on the web. Way lengths are not explicitly saved in the OSM data.</p>
<p>If you are doing a routing software, have a look at the many open source <a href="https://wiki.openstreetmap.org/wiki/Routing">routing</a> software which uses OSM data.</p>aseerel4c26Sun, 04 Oct 2015 21:21:29 +0100https://help.openstreetmap.org/questions/45705/how-to-calculate-street-length-from-osm-data/45706