Distance Matrix Calculate: Haversine formula

Hello,


I wanted  to calculate distances between geographic locations given as (latitude, longitude) pairs and I found a solution using Java Distance (attached example workflow). If you want result in miles, change the Earth to 3959 mi (6371 km).

If you are intrested in that topic (or different formulas) visit:
- http://www.movable-type.co.uk/scripts/latlong.html
- http://rosettacode.org/wiki/Haversine_formula
- https://stackoverflow.com/questions/120283/how-can-i-measure-distance-and-create-a-bounding-box-based-on-two-latitudelongi

 

Best,
Robert

2 Likes

fyi: The Haversine distance is available ready-to-use via the Palladian nodes.

-- Philipp

I know, I wanted to get another solution (more flexible).
The result in this case is the same.

Robert

Hi rchar01,
Thanks for providing this example. I have a question that maybe someone can help me with… I am trying to run this file but only have the distance calculate by region.
For example, if in my file I had an additional column, “region”, I would want to calculate points in region A only with other points in region A, points in region B only with other points in region B, etc. The only way I can think to do this is to split regions into their own separate input files, but that method is quite cumbersome.
I’ve tried using row filter and group nodes but haven’t been able to successfully pull this off.

Thanks again!
-Snowy

Could you give an example of the input data and the expected result (e.g. in csv file)?

Hi rchar01,
This is what I was hoping to achieve…
Input:
image

Output:
image

I ended up following my own suggestion but instead of having separate input files, I simply added a filter node. So the final product looks like this:
image

And the detail view:


The “constant value” node was used to reapply the region information.


I think I managed to solve this problem, I attached a workflow.
Please check the results.

distance_matrix_groups.knwf (29.4 KB)

— Robert

Hi Robert,
That looks like it works! Thanks so much for posting. I’ve learned a lot from your workflow and I am sure others will as well!

I am glad that I could help.

Robert

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