如何找到半径50公里范围内的所有城市?

时间:2016-04-26 03:28:33

标签: neo4j cypher

我在3.0.0-M01中看到为point()distance()添加了支持,但是我没有看到如何在密码查询中使用的示例。

基本上我在节点属性上有很多城市及其纬度/经度,我想找到半径50公里范围内的所有城市。有没有办法用Neo4j 3.0实现这个目标?

1 个答案:

答案 0 :(得分:2)

1)添加一些地方:

MERGE (a:Place {title: 'NY', latitude: 40.71427, longitude:-74.00597})
MERGE (b:Place {title: 'JC', latitude: 40.72816, longitude:-74.07764})
MERGE (c:Place {title: 'NA', latitude: 40.73566, longitude:-74.17237})
MERGE (d:Place {title: 'JC', latitude: 39.95234, longitude:-75.16379})

2)从纽约找到半径50公里范围内的城市:

MATCH (a:Place {title:'NY'})
    WITH a
MATCH (b:Place) WHERE id(b)<>id(a) 
    WITH a, b, distance( point(a), point(b) ) as dist 
        WHERE dist<=50000
RETURN 
    a.title, b.title, dist
ORDER BY dist DESC