Calculating driving distances by given lat and lon

How can I calculate distances from two points, if the coordinates are given?
E.g.: Berlin → Hamburg
the latitudes and longitudes from both cities are given
I need the driving distance not the airline

Hi @Fatih97
To calculate the driving distance you need an external API. Google Maps would be the obvious choice, but it’s not free. One alternative is the Routing API of TomTom. When you register you receive an API key and you can call the API’s endpoint of your interest using this syntax

``````join("https://api.tomtom.com/routing/1/calculateRoute/",
<1st point latitude>,
",",
<1st point longitude>,
":",
<2nd point latitude>,
",",
<2nd point longitude>,
"/json?key=",
<your API key>
)
``````

The result is a json file, from which you can extract the distance in meters between the points.
I’m not a regular user of the API, but it seems well constructed and it’s free for a reasonable amount of requests/month.

This is a simple workflow, with a test dataset of Italian cities. Of course, you must provide your API key in order to run it.
KNIME_project.knwf (44.3 KB)
Hope this is a good suggestion

6 Likes

Hi @Fatih97 , this is something that I’ve seen quite a few times recently, and I’ve seen some users using the Geo Distances node from the Palladian Extension.

I know sometimes some users cannot install “external” extension, so if that’s an issue, I’ve just created a component that you can use for distance calculation that uses basic Knime nodes (mostly the Math Formula) with no additional extensions required:

I basically use the Haversine Formula of:

and based on the Earth radius of 6,371 kilometres.

A simple use of my component is like this:

And for this input:

I get this result:

I test the same values on the Distance Calculator website:

It’s about the same results.

The column names of the 2 sets of latitudes and longitudes do not matter as the Component allows you to define which column is which:

EDIT: OK! I just noticed your last line there Just to clarify, my workflow is for air distance (or “as the crow files” distance), not driving
I’ll still leave it here though in case someone wants to calculate the geo distance

3 Likes

In addition to the already mentioned API of TomTom I would like to point out the different routing machines based on the data of the https://www.openstreetmap.org Many of them are described on the wiki page Routing - OpenStreetMap Wiki

Existing APIs are described in more detail on the developers page Routing - OpenStreetMap Wiki

Please respect the maximum workload you place there.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.