(net, points=True, lines=True, spatial_weights=False, nodeID="nodeID")
return _primal_to_gdf(
        net, points=points, lines=lines, spatial_weights=spatial_weights, nodeID=nodeID
    )
Convert ``networkx.Graph`` to LineString GeoDataFrame and Point GeoDataFrame.

    Automatically detects an ``approach`` of the graph and assignes edges and nodes to
    relevant geometry type.

    See the User Guide page :doc:`../../user_guide/graph/convert` for details.

    Parameters
    ----------
    net : networkx.Graph
        ``networkx.Graph``
    points : bool
        export point-based gdf representing intersections
    lines : bool
        export line-based gdf representing streets
    spatial_weights : bool
        export libpysal spatial weights for nodes (only for primal graphs)
    nodeID : str
        name of node ID column to be generated

    Returns
    -------
    GeoDataFrame
        Selected gdf or tuple of both gdfs or tuple of gdfs and weights

    See also
    --------
    gdf_to_nx

    Examples
    --------
    >>> import geopandas as gpd
    >>> df = gpd.read_file(momepy.datasets.get_path('bubenec'), layer='streets')
    >>> df.head(2)
                                                geometry
    0  LINESTRING (1603585.640 6464428.774, 1603413.2...
    1  LINESTRING (1603268.502 6464060.781, 1603296.8...
    >>> G = momepy.gdf_to_nx(df)

    Converting primal Graph to points as intersections and lines as street segments:

    >>> points, lines = momepy.nx_to_gdf(G)
    >>> points.head(2)
       nodeID                         geometry
    0       1  POINT (1603585.640 6464428.774)
    1       2  POINT (1603413.206 6464228.730)
    >>> lines.head(2)
                         geometry      mm_len  node_start  node_end
    0  LINESTRING (1603585.640...  264.103950           1         2
    1  LINESTRING (1603561.740...   70.020202           1         9

    Storing relationship between points/nodes as libpysal W object:

    >>> points, lines, W = momepy.nx_to_gdf(G, spatial_weights=True)
    >>> W
    <libpysal.weights.weights.W object at 0x7f8d01837210>

    Converting dual Graph to lines. Dual Graph does not export edges to GDF:

    >>> G = momepy.gdf_to_nx(df, approach="dual")
    >>> lines = momepy.nx_to_gdf(G)
    >>> lines.head(2)
                                                geometry      mm_len
    0  LINESTRING (1603585.640 6464428.774, 1603413.2...  264.103950
    1  LINESTRING (1603607.303 6464181.853, 1603592.8...  199.746503
Convert ``networkx.Graph`` to LineString GeoDataFrame and Point GeoDataFrame.
Convert networkx . Graph to LineString GeoDataFrame and Point GeoDataFrame .
def nx_to_gdf(net, points=True, lines=True, spatial_weights=False, nodeID="nodeID"):
    """
    Convert ``networkx.Graph`` to LineString GeoDataFrame and Point GeoDataFrame.

    Automatically detects an ``approach`` of the graph and assignes edges and nodes to
    relevant geometry type.

    See the User Guide page :doc:`../../user_guide/graph/convert` for details.

    Parameters
    ----------
    net : networkx.Graph
        ``networkx.Graph``
    points : bool
        export point-based gdf representing intersections
    lines : bool
        export line-based gdf representing streets
    spatial_weights : bool
        export libpysal spatial weights for nodes (only for primal graphs)
    nodeID : str
        name of node ID column to be generated

    Returns
    -------
    GeoDataFrame
        Selected gdf or tuple of both gdfs or tuple of gdfs and weights

    See also
    --------
    gdf_to_nx

    Examples
    --------
    >>> import geopandas as gpd
    >>> df = gpd.read_file(momepy.datasets.get_path('bubenec'), layer='streets')
    >>> df.head(2)
                                                geometry
    0  LINESTRING (1603585.640 6464428.774, 1603413.2...
    1  LINESTRING (1603268.502 6464060.781, 1603296.8...
    >>> G = momepy.gdf_to_nx(df)

    Converting primal Graph to points as intersections and lines as street segments:

    >>> points, lines = momepy.nx_to_gdf(G)
    >>> points.head(2)
       nodeID                         geometry
    0       1  POINT (1603585.640 6464428.774)
    1       2  POINT (1603413.206 6464228.730)
    >>> lines.head(2)
                         geometry      mm_len  node_start  node_end
    0  LINESTRING (1603585.640...  264.103950           1         2
    1  LINESTRING (1603561.740...   70.020202           1         9

    Storing relationship between points/nodes as libpysal W object:

    >>> points, lines, W = momepy.nx_to_gdf(G, spatial_weights=True)
    >>> W
    <libpysal.weights.weights.W object at 0x7f8d01837210>

    Converting dual Graph to lines. Dual Graph does not export edges to GDF:

    >>> G = momepy.gdf_to_nx(df, approach="dual")
    >>> lines = momepy.nx_to_gdf(G)
    >>> lines.head(2)
                                                geometry      mm_len
    0  LINESTRING (1603585.640 6464428.774, 1603413.2...  264.103950
    1  LINESTRING (1603607.303 6464181.853, 1603592.8...  199.746503
    """
    # generate nodes and edges geodataframes from graph
    primal = None
    if "approach" in net.graph.keys():
        if net.graph["approach"] == "primal":
            primal = True
        elif net.graph["approach"] == "dual":
            return _dual_to_gdf(net)
        else:
            raise ValueError(
                f"Approach {net.graph['approach']} is not supported. "
                "Use 'primal' or 'dual'."
            )

    if not primal:
        import warnings

        warnings.warn("Approach is not set. Defaulting to 'primal'.")

    for nid, n in enumerate(net):
        net.nodes[n][nodeID] = nid

    return _primal_to_gdf(
        net, points=points, lines=lines, spatial_weights=spatial_weights, nodeID=nodeID
    )
def nx_to_gdf ( net , points = True , lines = True , spatial_weights = False , nodeID = "nodeID" ) : # generate nodes and edges geodataframes from graph primal = None if "approach" in net . graph . keys ( ) : if net . graph [ "approach" ] == "primal" : primal = True elif net . graph [ "approach" ] == "dual" : return _dual_to_gdf ( net ) else : raise ValueError ( f"Approach {net.graph['approach']} is not supported. " "Use 'primal' or 'dual'." ) if not primal : import warnings warnings . warn ( "Approach is not set. Defaulting to 'primal'." ) for nid , n in enumerate ( net ) : net . nodes [ n ] [ nodeID ] = nid return _primal_to_gdf ( net , points = points , lines = lines , spatial_weights = spatial_weights , nodeID = nodeID )