【问题标题】:osmnx: project point to street segmentsosmnx:项目点到街道段
【发布时间】:2021-01-14 04:41:56
【问题描述】:

我有一个由 lat 和 lon 给出的点,我想通过最小欧几里得距离找到离该点最近的边。例如

import osmnx as ox
track = [(40.7052, -74.0069)]
fig, ax = ox.plot_graph(G, show=False, close=False)
for pairs in track:
    ax.scatter(pairs[1], pairs[0], c='red')
plt.show()

ox.distance.get_nearest_edge(G, track, return_geom=True, return_dist=True)

我明白了

(2350521192,2350521202,0,
<shapely.geometry.linestring.LineString at 0x16569aa30>,
162.22242578930698)

它输出边的顶点及其几何形状。点和最近边之间的距离是 162。但是如何找到我的点在最近边上的投影?

【问题讨论】:

  • 你能提供一个可重现的例子吗?您的代码无法运行。

标签: line openstreetmap projection osmnx


【解决方案1】:

这是一个完整的最小工作示例:

import osmnx as ox
from shapely.geometry import Point
ox.config(use_cache=True, log_console=True)

# create point tuple as (lat, lng)
point = (40.7052, -74.0069)
G = ox.graph_from_point(point, network_type='drive')
u, v, k, edge_geom, dist = ox.distance.get_nearest_edge(G, point, return_geom=True, return_dist=True)

# create shapely point geometry object as (x, y), that is (lng, lat)
point_geom = Point(reversed(point))

# use shapely to find the point along the edge that is closest to the reference point
nearest_point_on_edge = edge_geom.interpolate(edge_geom.project(point_geom))
nearest_point_on_edge.coords[0]

【讨论】:

  • 非常感谢。我也只是使用 shapely.ops 中的最近点来解决这个问题。我应该花一些时间浏览图书馆的纪录片。我真的不熟悉他们。我是康奈尔大学的博士生(你来的时候想去听你的演讲,但当时我不得不教书)。我为网络数据开发了一个非参数回归估计器,该方法可用于网络上的密度估计或变系数回归。我完成了理论开发和模拟研究,但实施让我很头疼。我的编码能力很弱。
猜你喜欢
  • 2020-06-24
  • 2020-08-27
  • 2020-07-08
  • 2021-09-10
  • 1970-01-01
  • 1970-01-01
  • 2014-03-02
  • 1970-01-01
  • 2020-09-15
相关资源
最近更新 更多