This does a proper job of building a relationship between two airports where I then indicate the distance between the airports in both miles and kilometers. The query build a cartesian product - is there a more efficient slash elegant way of performing this? I have tested this with a small subset of airports (8 airports, 64 relationships), but fear this will not scale to 10's of thousand of airports.
MATCH (a:Airport), (b:Airport)
WHERE
a.iata_code <> b.iata_code
WITH
a, b,
point({latitude:a.latitude_deg, longitude:a.longitude_deg, height: a.elevation_ft / 3.281}) AS p_a,
point({latitude:b.latitude_deg, longitude:b.longitude_deg, height: b.elevation_ft / 3.281}) AS p_b
MERGE
(a)-[:DISTANCE_BETWEEN {distance_miles: round(point.distance(p_a, p_b) / 1609, 1),
distance_kilometers: round(point.distance(p_a, p_b) / 1000, 1)}]-(b)
The Cartesian product is equivalent to a matrix multiplication so this clause allows you to do the calculation only in one direction. Instead of doing n² operations, there are (n(n-1))/2 operations. I don't know if it's clear