Created
May 18, 2019 11:30
-
-
Save vladbatushkov/9a7599d96b69f295e656e8f5c1c7f554 to your computer and use it in GitHub Desktop.
Map of museums.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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