aba2s
aba2s

Reputation: 520

Visualize two way streets offset from each other

I am using osmnx package to visualize a street network. I would like to visualize both (two) lanes in opposite directions of a road. I am using this code https://github.com/gboeing/osmnx/issues/162

But I don't know how to add the output point on the map. Could you please help me? Or if you know another package with this possibility, please share. Lots of thanks

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)

Upvotes: 2

Views: 231

Answers (1)

rtphokie
rtphokie

Reputation: 686

I'm finding this question interesting as well for the use case of really finding one-way streets. The oneway attribute in OSM also shows up as True for each direction of a divided highway.

You can get close by filtering out by highway type (OneWay == True and Highway == motorway) but checking for parallel as is done above seems much more accurate for my use case.

Upvotes: 1

Related Questions