(G, gdf_network, fields, angles, multigraph, angle)
Generate dual graph
    Helper for gdf_to_nx.
Generate dual graph
    Helper for gdf_to_nx.
Generate dual graph Helper for gdf_to_nx .
def _generate_dual(G, gdf_network, fields, angles, multigraph, angle):
    """
    Generate dual graph
    Helper for gdf_to_nx.
    """
    G.graph["approach"] = "dual"
    key = 0

    sw = libpysal.weights.Queen.from_dataframe(gdf_network, silence_warnings=True)
    cent = gdf_network.geometry.centroid
    gdf_network["temp_x_coords"] = cent.x
    gdf_network["temp_y_coords"] = cent.y

    for i, row in enumerate(gdf_network.itertuples()):
        centroid = (row.temp_x_coords, row.temp_y_coords)
        data = [f for f in row][1:-2]
        attributes = dict(zip(fields, data))
        G.add_node(centroid, **attributes)

        if sw.cardinalities[i] > 0:
            for n in sw.neighbors[i]:
                start = centroid
                end = (
                    gdf_network["temp_x_coords"].iloc[n],
                    gdf_network["temp_y_coords"].iloc[n],
                )
                p0 = row.geometry.coords[0]
                p1 = row.geometry.coords[-1]
                geom = gdf_network.geometry.iloc[n]
                p2 = geom.coords[0]
                p3 = geom.coords[-1]
                points = [p0, p1, p2, p3]
                shared = [x for x in points if points.count(x) > 1]
                if shared:  # fix for non-planar graph
                    remaining = [e for e in points if e not in [shared[0]]]
                    if len(remaining) == 2:
                        if angles:
                            angle_value = _angle(remaining[0], shared[0], remaining[1])
                            if multigraph:
                                G.add_edge(start, end, key=0, **{angle: angle_value})
                                key += 1
                            else:
                                G.add_edge(start, end, **{angle: angle_value})
                        else:
                            if multigraph:
                                G.add_edge(start, end, key=0)
                                key += 1
                            else:
                                G.add_edge(start, end)
def _generate_dual ( G , gdf_network , fields , angles , multigraph , angle ) : G . graph [ "approach" ] = "dual" key = 0 sw = libpysal . weights . Queen . from_dataframe ( gdf_network , silence_warnings = True ) cent = gdf_network . geometry . centroid gdf_network [ "temp_x_coords" ] = cent . x gdf_network [ "temp_y_coords" ] = cent . y for i , row in enumerate ( gdf_network . itertuples ( ) ) : centroid = ( row . temp_x_coords , row . temp_y_coords ) data = [ f for f in row ] [ 1 : - 2 ] attributes = dict ( zip ( fields , data ) ) G . add_node ( centroid , * * attributes ) if sw . cardinalities [ i ] > 0 : for n in sw . neighbors [ i ] : start = centroid end = ( gdf_network [ "temp_x_coords" ] . iloc [ n ] , gdf_network [ "temp_y_coords" ] . iloc [ n ] , ) p0 = row . geometry . coords [ 0 ] p1 = row . geometry . coords [ - 1 ] geom = gdf_network . geometry . iloc [ n ] p2 = geom . coords [ 0 ] p3 = geom . coords [ - 1 ] points = [ p0 , p1 , p2 , p3 ] shared = [ x for x in points if points . count ( x ) > 1 ] if shared : # fix for non-planar graph remaining = [ e for e in points if e not in [ shared [ 0 ] ] ] if len ( remaining ) == 2 : if angles : angle_value = _angle ( remaining [ 0 ] , shared [ 0 ] , remaining [ 1 ] ) if multigraph : G . add_edge ( start , end , key = 0 , * * { angle : angle_value } ) key += 1 else : G . add_edge ( start , end , * * { angle : angle_value } ) else : if multigraph : G . add_edge ( start , end , key = 0 ) key += 1 else : G . add_edge ( start , end )