在过去的两个周末中,我一直在处理一些运输数据,并且我想运行A *算法来查找两个车站之间的最快路线。
A *算法将一个EstimateEvaluator作为其参数之一,然后该评估器查看节点的经度/纬度,以确定一条路径是否值得遵循。 因此,我需要为每个测站添加纬度/经度,而且我很难找到数据集中所有点的定位日期。
幸运的是,我倾向于在测站的两侧各有经度/纬度两点,因此我可以算出中点作为丢失点的近似值。
我找到了一篇文章,该文章定义了可以用来执行此操作的公式 ,并且有一个StackOverflow帖子 ,其中包含一些实现该公式的Java代码。
我想找到萨里码头(Surrey Quays)站(51.4931963543,-0.0475185810)和火车线上更南的点(51.47908,-0.05393950)之间的中点。 我编写了以下Cypher查询来计算这一点:
WITH 51.4931963543 AS lat1, -0.0475185810 AS lon1,
51.47908 AS lat2 , -0.05393950 AS lon2
WITH radians(lat1) AS rlat1, radians(lon1) AS rlon1,
radians(lat2) AS rlat2, radians(lon2) AS rlon2,
radians(lon2 - lon1) AS dLon
WITH rlat1, rlon1, rlat2, rlon2,
cos(rlat2) * cos(dLon) AS Bx,
cos(rlat2) * sin(dLon) AS By
WITH atan2(sin(rlat1) + sin(rlat2),
sqrt( (cos(rlat1) + Bx) * (cos(rlat1) + Bx) + By * By )) AS lat3,
rlon1 + atan2(By, cos(rlat1) + Bx) AS lon3
RETURN degrees(lat3) AS midLat, degrees(lon3) AS midLon
╒═════════════════╤═════════════════════╕
│midLat │midLon │
╞═════════════════╪═════════════════════╡
│51.48613822097523│-0.050729537454086385│
└─────────────────┴─────────────────────┘
右侧的Google Maps屏幕截图显示了顶部和底部的初始点以及中间的中间点。 这并不完美; 理想情况下,我希望中点在轨道上,但是对于算法而言,我认为这已经足够了。
现在,我需要填写无位置站的经纬度!
翻译自: https://www.javacodegeeks.com/2016/11/neo4j-find-midpoint-two-latlongs.html