Skip to content

Instantly share code, notes, and snippets.

@vladbatushkov
Created May 18, 2019 11:30
Show Gist options
  • Save vladbatushkov/9a7599d96b69f295e656e8f5c1c7f554 to your computer and use it in GitHub Desktop.
Save vladbatushkov/9a7599d96b69f295e656e8f5c1c7f554 to your computer and use it in GitHub Desktop.
Map of museums.
MATCH (m1:Museum), (m2:Museum)
WHERE id(m1) <> id(m2)
WITH m1, collect({ toId: id(m2), dist: apoc.math.round(distance(m1.location, m2.location) / 1000, 1) }) as distances
WITH m1, filter(x IN distances WHERE x.dist > 0.0) as needToWalk
WITH m1, apoc.coll.sortMaps(needToWalk, '^dist') as sorted
UNWIND sorted[0..3] as nearm
MATCH (m:Museum)
WHERE NOT (m1)-[:WALK]-(m) AND id(m) = nearm.toId
MERGE (m1)-[:WALK { distanceKm: nearm.dist }]->(m)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment