【发布时间】:2021-06-04 19:06:44
【问题描述】:
我在地球表面有 9 个点(经度,纬度,度数)如下。
XY = [(100, 10), (100, 11), (100, 13), (101, 10), (101, 11), (101, 13), (103, 10), (103, 11), (103, 13)]
print (len(XY))
# 9
我想提取彼此相距至少 3 度的点。
我试过如下。
results = []
for point in XY:
x1,y1 = point
for result in results:
x2,y2 = result
distance = math.hypot(x2 - x1, y2 - y1)
if distance >= 3:
results.append(point)
print (results)
但是输出是空的。
编辑 2
from sklearn.metrics.pairwise import haversine_distances
from math import radians
results = []
for point in XY:
x1,y1 = [radians(_) for _ in point]
for result in results:
distance = haversine_distances((x1,y1), (x2,y2))
print (distance)
if distance >= 3:
results.append(point)
print (results)
结果还是空
编辑 3
results = []
for point in XY:
x1,y1 = point
for point in XY:
x2,y2 = point
distance = math.hypot(x2 - x1, y2 - y1)
print (distance)
if distance >= 3:
results.append(point)
print (results)
print (len(results))
# 32 # unexpected len
【问题讨论】:
-
math.hypot()计算点之间的欧几里得距离,但是您需要确定它们之间相对于某些线段(可能是水平轴)的角距离。 -
@martineau 我试过scikit-learn.org/stable/modules/generated/…
-
我认为问题出在 pythonic 循环中
-
如果值是经度和纬度,那么它们之间的角距离是从地球中心到这些点的两条假想线之间的角距离。不管如何计算或计算什么,你是对的,循环的编写方式存在问题。您需要遍历 pairs 点并比较计算值。您还需要将每一个与所有其他的进行比较。
标签: python python-3.x geometry coordinates