【问题标题】:What is the fastest way to generate latitude and longitude knowing start and end points知道起点和终点的生成纬度和经度的最快方法是什么
【发布时间】:2021-12-05 22:36:03
【问题描述】:

我有一个 shape (30000, 2000, 2) 的 Numpy 数组,其中每一行应该有 2000 个纬度和经度点,它们之间的距离相等且方向相同。问题是,每一行都有缺失点。对于每一行,只有起点和终点的纬度和经度(在 CRS WSG84 中)是已知的,而其余点则缺失。 例如单行可以是这样的:

latlonPoints[0,:] = [(48.778767, -123.903275),?,?,?,...,(49.887672, -122.49999)]

使用每一行的起点和终点,我们可以很容易地计算出两点之间的距离(有时是几公里)和角度(方位角)。然后使用距离和方位,我们可以使用geopy or other methods 生成其余点。但是,对于所有行和每一行的所有元素,使用 for 循环的迭代太慢了。 python中计算缺失点的最快方法是什么? 这是我已经实现的,它工作得很好但很慢:

    for idx, row in enumerate(latlonPoints):
    lat_start = row[0]
    long_start = row[1]
    coords1 = (lat_start, long_start)
    lat_end = row[2]
    long_end = row[3]
    bearing, back_azimuth, distance = geodesic1.inv(long_start, lat_start, long_end, lat_end)
    step_size = distance/(latlonPoints.shape[1] -1)
    latlon_row = []
    for i in range (0,latlonPoints.shape[1]):
        dist = i * step_size
        destination = geodesic(kilometers=dist / 1000).destination(coords1, bearing)
        latlon_row.append((destination.latitude,destination.longitude))
    latlonPoints[idx,:] = np.array(latlon_row)

【问题讨论】:

  • 列表推导,numpy循环什么的或者一个数学公式(最快的),否则使用一些更快的语言
  • This 回答可能会有所帮助。该库似乎能够在我的机器上在一毫秒内插入 2000 个点。
  • 如果你真的只是跨越几公里,没有必要使用球坐标。只做线性插值。差异不会很明显。
  • @hilberts_drinking_problem "pyproj.Geod(ellps='WGS84')" 很快就能解决问题。谢谢

标签: python numpy gis


【解决方案1】:

@hilberts_drinking_problem 使用poproj 和 Geod 回答了这个问题,我可以生成多个点给定一个初始点和终点。它返回一个经度/纬度对列表,描述沿初始点和终点之间的测地线等间距的 npts 中间点。

from pyproj import Geod

extra_points = pyproj.Geod(ellps='WGS84')

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-11-30
    • 2016-02-03
    • 2016-12-02
    • 2018-08-17
    • 2019-10-08
    • 1970-01-01
    • 2010-11-03
    相关资源
    最近更新 更多