我正在处理csv文件中的数据,该文件包含三列数据:house、houseLong、houseLat,其中house是房屋的唯一编号,houseLong是房屋位置的经度,houseLat是房屋位置的纬度。
示例数据如下:
第1行1, 22.6932, 100.5347
第2行2, 25.6589, 98.5679
第3行3, 33.1674, 66.3287
一直到最后一行
第100行100, 37.6532, 95.3567
我已经将所有这些数据导入到Neo4j中-节点被标记为House。
对于每一所房子,我试图计算出它与其他房子之间的距离。
所以对于房屋1,我尝试得到从房屋1到房屋2,房屋1到房屋3的距离,依此类推,直到房屋100。
对于房子2,我试图得到从房子2到房子1,房子2到房子3的距离,依此类推,直到房子100。
我不确定实现此查询的最佳方式。现在我能做的就是:
MATCH (h1: House {house: 1}), (h2: House {house: 2})
WITH point({longitude: h1.houseLong, latitude: h1.houseLat}) AS point1, point({longitude: h2.houseLong, latitude: h2.houseLat}) AS point2
RETURN round(distance(point1, point2)) AS Distance上面的查询给出了房子1和房子2之间的距离,但我不确定如何为查询中的每个房子缩放这个距离。
发布于 2020-11-04 03:07:37
这将为您提供按house值排序的距离:
MATCH (h1: House), (h2: House)
WHERE h1 <> h2
RETURN
h1, h2,
round(distance(
point({longitude: h1.houseLong, latitude: h1.houseLat}),
point({longitude: h2.houseLong, latitude: h2.houseLat}))) AS dist
ORDER BY h1.house, h2.house注意:每一对房子将被表示两次(以相反的顺序),这显然是您想要的。
https://stackoverflow.com/questions/64657117
复制相似问题