Skip to main content
`Ctrl`+`K`

# aequilibrae.transit.TransitGraphBuilder

class aequilibrae.transit.TransitGraphBuilder(public_transport_conn, period_id: int = 1, time_margin: int = 0, projected_crs: str = 'EPSG:3857', num_threads: int = -1, seed: int = 124, geometry_noise: bool = True, noise_coef: float = 1e-05, with_inner_stop_transfers: bool = False, with_outer_stop_transfers: bool = False, with_walking_edges: bool = True, distance_upper_bound: float = inf, blocking_centroid_flows: bool = True, connector_method: str = 'nearest_neighbour', max_connectors_per_zone: int = -1)

  Graph builder for the transit assignment Spiess & Florian algorithm.

  Arguments:

    public_transport_conn (`sqlite3.Connection`): Connection to the `public_transport.sqlite` database.

    period_id (`int`): Period id for the period to be used. Preferred over start and end.

    time_margin (`int`): Time margin, extends the `start` and `end` times by `time_margin` ([`start`, `end`] becomes [`start` - `time_margin`, `end` + `time_margin`]), in order to include more trips when computing mean values. Defaults to `0`.

    projected_crs (`str`): Projected CRS of the network, intended for more accurate distance calculations. Defaults to `"EPSG:3857"`, Spherical Mercator.

    num_threads (`int`): Number of threads to be used where possible. Defaults to `-1`, using all available threads.

    seed (`int`): Seed for `self.rng`. Defaults to `124`.

    geometry_noise (`bool`): Whether to use noise in geometry creation, in order to avoid colocated nodes. Defaults to `True`.

    noise_coef (`float`): Scaling factor of the noise. Defaults to `1.0e-5`.

    with_inner_stop_transfers (`bool`): Whether to create transfer edges within parent stations. Defaults to `False`.

    with_outer_stop_transfers (`bool`): Whether to create transfer edges between parent stations. Defaults to `False`.

    with_walking_edges (`bool`): Whether to create walking edges between distinct stops of each station. Defaults to `True`.

    distance_upper_bound (`float`): Upper bound on connector distance. Defaults to `np.inf`.

    blocking_centroid_flows (`bool`): Whether to block flow through centroids. Defaults to `True`.

    max_connectors_per_zone (`int`): Maximum connectors per zone. Defaults to `-1` for unlimited.

  __init__(public_transport_conn, period_id: int = 1, time_margin: int = 0, projected_crs: str = 'EPSG:3857', num_threads: int = -1, seed: int = 124, geometry_noise: bool = True, noise_coef: float = 1e-05, with_inner_stop_transfers: bool = False, with_outer_stop_transfers: bool = False, with_walking_edges: bool = True, distance_upper_bound: float = inf, blocking_centroid_flows: bool = True, connector_method: str = 'nearest_neighbour', max_connectors_per_zone: int = -1)

  Methods

  `__init__`(public_transport_conn[, period_id, ...]) |
  `add_zones`(zones[, from_crs]) | Add zones as ODs.
  `convert_demand_matrix_from_zone_to_node_ids`(...) | Convert a sparse demand matrix from `zone_id`'s to the corresponding `node_id`'s.
  `create_additional_db_fields`() | Create the additional required entries in the tables.
  `create_graph`() | Create the SF transit graph (vertices and edges).
  `create_line_geometry`([method, graph]) | Create the LineString for each edge.
  `create_od_node_mapping`() | Build a dataframe mapping the centroid node ids with to transport assignment zone ids.
  `from_db`(public_transport_conn, period_id, ...) | Create a SF graph instance from an existing database save.
  `save`([robust]) | Save the current graph to the public transport database.
  `save_config`() |
  `save_edges`([recreate_line_geometry]) | Save the contents of self.edges to the public transport database.
  `save_vertices`([robust]) | Write the vertices DataFrame to the public transport database.
  `to_transit_graph`() | Create an AequilibraE `TransitGraph` object from an SF graph builder.

  Attributes

  `config` |

  add_zones(zones, from_crs: str | None = None)

    Add zones as ODs.

    Arguments:

      zones (`pd.DataFrame`): DataFrame containing the zoning information. Columns must include `zone_id` and `geometry`.

      from_crs (`str`): The CRS of the `geometry` column of `zones`. If not provided it’s assumed that the geometry is already in `self.projected_crs`. If provided, the geometry will be projected to `self.projected_crs`. Defaults to `None`.

  convert_demand_matrix_from_zone_to_node_ids(demand_matrix, o_zone_col='origin_zone_id', d_zone_col='destination_zone', demand_col='demand')

    Convert a sparse demand matrix from `zone_id`’s to the corresponding `node_id`’s.

  create_additional_db_fields()

    Create the additional required entries in the tables.

  create_graph()

    Create the SF transit graph (vertices and edges).

  create_line_geometry(method='direct', graph='w')

    Create the LineString for each edge.

    The direct method creates a straight line between all points.

    The connect project match method uses the existing line geometry within the project to create more accurate line strings. It creates a line string that matches the path between the shortest path between the project nodes closest to either end of the access and egress connectors.

    Project graphs must be built for the “connector project match” method.

    Arguments:

      method (`str`): Must be either `"direct"` or `"connector project match"`. If method is `"direct"`, `graph` argument is ignored.

      graph (`str`): Must be a key within `project.network.graphs`.

  create_od_node_mapping()

    Build a dataframe mapping the centroid node ids with to transport assignment zone ids.

  classmethod from_db(public_transport_conn, period_id: int, **kwargs)

    Create a SF graph instance from an existing database save.

    Assumes the database was constructed with the provided save methods. No checks are performed to see if the provided arguments are compatible with the saved graph.

    All arguments are forwarded to the constructor.

    Arguments:

      public_transport_conn (`sqlite3.Connection`): Connection to the ‘public_transport.sqlite’ database.

  save(robust=True)

    Save the current graph to the public transport database.

    Arguments:

      recreate_line_geometry (`bool`): Whether to recreate the line strings for the edges as direct lines. Defaults to `False`.

  save_config()
  save_edges(recreate_line_geometry=False)

    Save the contents of self.edges to the public transport database.

    If no geometry for the edges is present or `recreate_line_geometry` is `True`, direct lines will be created.

    Arguments:

      recreate_line_geometry (`bool`): Whether to recreate the line strings for the edges as direct lines. Defaults to `False`.

  save_vertices(robust=True)

    Write the vertices DataFrame to the public transport database.

    Within the database nodes may not exist at the exact same point in space, provide `robust=True` to move the nodes slightly.

    Arguments:

      robust (`bool`): Whether to move stack nodes slightly before saving. Defaults to `True`.

  to_transit_graph() → TransitGraph

    Create an AequilibraE `TransitGraph` object from an SF graph builder.

  property config