问题描述
我正在使用 osmnx 包来可视化街道网络。我想想象一条道路相反方向的两条(两条)车道。我正在使用此代码 https://github.com/gboeing/osmnx/issues/162
但是我不知道如何在地图上添加输出点。请你帮助我好吗?或者,如果您知道另一个具有这种可能性的软件包,请分享。非常感谢
place_name = 'Cergy,France'
G = ox.graph_from_place(place_name,network_type = 'drive')
lines=[]
for u,v,data in G.edges(keys=False,data=True):
if 'geometry' in data:
# if it has a geometry attribute (a list of line segments),add them
# to the list of lines to plot
xs,ys = data['geometry'].xy
points = list(zip(xs,ys))
#parallel shift distance
h = 1
if not data['oneway']:
# for each point excluding the start point and end point,shift point based on
# line to next point
transformed_points = [points[0]]
# get pairs of points on the line segment
for p1,p2 in zip(points[1:],points[2:]):
(x1,y1) = parallel_point_shift(p1,p2,h)[0]
transformed_points.append((x1,y1))
transformed_points.append(points[-1])
points = transformed_points
lines.append(list(points))
else:
# if it doesn't have a geometry attribute,the edge is a straight
# line from node to node
x1 = G.nodes[u]['x']
y1 = G.nodes[u]['y']
x2 = G.nodes[v]['x']
y2 = G.nodes[v]['y']
if not data['oneway']:
((x1,y1),(x2,y2)) = parallel_point_shift((x1,y2),h)
line = [(x1,y2)]
lines.append(line)
解决方法
我发现这个问题对于 really 寻找单向街道的用例也很有趣。 OSM 中的 oneway 属性对于分隔公路的每个方向也显示为 True。
您可以通过按高速公路类型(OneWay == True 和 Highway == 高速公路)过滤来接近,但对于我的用例来说,如上所述检查平行似乎更准确。