【问题标题】:Shapely linestring .length units匀称的线串 .length 单位
【发布时间】:2020-05-22 13:15:07
【问题描述】:

我正在尝试在 Shapely 中查找线串的长度(以米为单位),但似乎无法达到预期的结果。几乎可以肯定我在坐标系方面犯了一些错误,但我无法弄清楚。

下面是单行的一些简化代码:

from shapely.geometry import LineString
line = LineString([(12875996.563923, -3940011.116702), (12872802.929335, -3937989.118438)])
line.crs = 'EPSG:3857'
line.length

输出为 3779.92m。但是,根据我的测量,它应该是 ~3159m。

这是基于检查以下站点的点(两个环形交叉路口的中心)的位置,然后在 Google 地球中测量它们之间的位置。

第 1 点: http://epsg.io/map#srs=3857&x=12875996.563923&y=-3940011.116702&z=14&layer=streets
第 2 点: http://epsg.io/map#srs=3857&x=12872802.929468&y=-3937989.118538&z=17&layer=streets

【问题讨论】:

标签: python spatial coordinate-systems shapely


【解决方案1】:

为了证明,来自匀称几何的line.length 只是一个欧几里得距离,可以这样计算:

import math
x1, y1 = (12875996.563923, -3940011.116702)
x2, y2 = (12872802.929335, -3937989.118438)
math.hypot(x2-x1,  y2-y1)  # 3779.91783790157

要使用pyproj 模块获得正确的距离,请执行以下步骤:

import pyproj  #v2.4.1
x1, y1 = (12875996.563923, -3940011.116702)
x2, y2 = (12872802.929335, -3937989.118438)
lon1, lat1 = pyproj.Proj("epsg:3857")(x1, y1, inverse=True)
lon2, lat2 = pyproj.Proj("epsg:3857")(x2, y2, inverse=True)
_,_,dist_km = pyproj.Geod(ellps='WGS84').inv(lon1, lat1, lon2, lat2)
dist_km   # 3157.214113925091

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-09
    • 1970-01-01
    • 1970-01-01
    • 2013-01-05
    • 1970-01-01
    相关资源
    最近更新 更多