# spaghetti.element_as_gdf

spaghetti.element_as_gdf(net, vertices=False, arcs=False, pp_name=None, snapped=False, routes=None, id_col='id', geom_col=None)

  Return a `geopandas.GeoDataFrame` of network elements. This can be (a) the vertices of a network; (b) the arcs of a network; (c) both the vertices and arcs of the network; (d) the raw point pattern associated with the network; (e) the snapped point pattern of (d); or (f) the shortest path routes between point observations.

  Parameters:
    net `spaghetti.Network`

      A spaghetti network object.

    vertices bool

      Extract the network vertices (`True`). Default is `False`.

    arcs bool

      Extract the network arcs (`True`). Default is `False`.

    pp_name `python:str`

      Name of the `network.PointPattern` to extract. Default is `None`.

    snapped bool

      If extracting a `network.PointPattern`, set to `True` for snapped point locations along the network. Default is `False`.

    routes `python:dict`

      See `paths` from `spaghetti.Network.shortest_paths`. Default is `None`.

    id_col `python:str`

      `geopandas.GeoDataFrame` column name for IDs. Default is `"id"`. When extracting routes this creates an (origin, destination) tuple.

    geom_col `python:str`

      Deprecated and will be removed in the minor release. `geopandas.GeoDataFrame` column name for IDs. Default is `"id"`. When extracting routes this creates an (origin, destination) tuple.

  Returns:
    points `geopandas.GeoDataFrame`

      Network point elements (either vertices or `network.PointPattern` points) as a `geopandas.GeoDataFrame` of `shapely.geometry.Point` objects with an `"id"` column and `"geometry""` column. If the network object has a `network_component_vertices` attribute, then component labels are also added in a column.

    lines `geopandas.GeoDataFrame`

      Network arc elements as a `geopandas.GeoDataFrame` of `shapely.geometry.LineString` objects with an `"id"` column and `"geometry"` column. If the network object has a `network_component_labels` attribute, then component labels are also added in a column.

    paths `geopandas.GeoDataFrame`

      Shortest path routes along network arc elements as a `geopandas.GeoDataFrame` of `shapely.geometry.LineString` objects with an `"id"` (see `spaghetti.Network.shortest_paths()`) column and `"geometry"` column.

  Raises:
    `KeyError`

      In order to extract a `network.PointPattern` it must already be a part of the network object. This exception is raised when a `network.PointPattern` is being extracted that does not exist within the network object.

  See also

  `geopandas.GeoDataFrame`

  Notes

  When both network vertices and arcs are desired, the variable declaration must be in the order: <vertices>, <arcs>.

  Examples

  Instantiate a network object.

      >>> import spaghetti
      >>> from libpysal import examples
      >>> ntw = spaghetti.Network(examples.get_path("streets.shp"))

  Extract the network elements (vertices and arcs) as `geopandas.GeoDataFrame` objects.

      >>> vertices_df, arcs_df = spaghetti.element_as_gdf(
      ...     ntw, vertices=True, arcs=True
      ... )

  Examine the first vertex. It is a member of the component labeled `0`.

      >>> vertices_df.loc[0]
      id                                            0
      geometry      POINT (728368.04762 877125.89535)
      comp_label                                    0
      Name: 0, dtype: object

  Calculate the total length of the network.

      >>> arcs_df.geometry.length.sum()
      np.float64(104414.09200823458)