如何在 Neo4j 中创建空间索引?

How to create Spatical Index in Neo4j?

我的 neo4j 数据库中有一些现有数据。我想根据节点存在的经度和纬度计算从一个节点到另一个节点的距离。为此,我想在现有数据上创建空间索引,但我不知道如何创建该索引。

您是否使用空间扩展来创建 OSMLayer?如果没有,而您只想要点之间的测地线,则可以使用 haversine 函数。

http://neo4j.com/docs/stable/query-functions-mathematical.html#functions-haversin

CREATE (ber:City { lat: 52.5, lon: 13.4 }),(sm:City { lat: 37.5, lon: -122.3 })
RETURN 2 * 6371 * asin(sqrt(haversin(radians(sm.lat - ber.lat))+ cos(radians(sm.lat))*
  cos(radians(ber.lat))* haversin(radians(sm.lon - ber.lon)))) AS dist