我使用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,y1),(x2,y2), h)
line = [(x1, y1), (x2, y2)]
lines.append(line)
我发现这个问题对于真的寻找单行道的用例也很有趣。OSM中的“单向”属性对于分割公路的每个方向也显示为True
您可以通过按高速公路类型(one-way==True和highway==motorway)进行筛选来接近,但对于我的用例,上面所做的并行检查似乎更准确
相关问题 更多 >
编程相关推荐