Jot*_*ani 1 python tuples list coordinates
给定一个包含坐标的元组列表,我想找到哪个坐标最接近我在输入中给出的坐标:
cooList = [(11.6702634, 72.313323), (31.67342698, 78.465323)]
coordinate = (11.6702698, 78.113323)
takenearest(myList, myNumber)
...
(11.6702634, 72.313323)
Run Code Online (Sandbox Code Playgroud)
请告诉我...
对于您的数据
cooList = [(11.6702634, 72.313323), (31.67342698, 78.465323)]
coordinate = (11.6702698, 78.113323)
Run Code Online (Sandbox Code Playgroud)
最短的Pythonic答案是:
nearest = min(cooList, key=lambda x: distance(x, coordinate))
Run Code Online (Sandbox Code Playgroud)
使用函数distance(a, b)返回点之间的距离a并b作为浮点数,您必须自己定义.
现在你必须决定如何计算距离:使用简单的a² + b² = c²,一些地理公式或专用库.
| 归档时间: |
|
| 查看次数: |
3328 次 |
| 最近记录: |