aequilibrae.project.network.connector_creation#

Functions

bulk_connector_creation(conn, project_nodes, ...)

Creates or updates centroid connectors between zone centroids and network nodes.

connector_creation(zone_id, mode_id, ...[, ...])

k_nearest(k, centroids, nodes, ...)

Finds the k nearest nodes to each centroid using a KDTree spatial index.

k_nearest_in_zone(k, zones, centroids, ...)

Finds the k nearest nodes within each zone to the corresponding centroid.

normalise_mode_strings(x)

Normalises a collection of mode strings by sorting unique characters.

aequilibrae.project.network.connector_creation.bulk_connector_creation(conn: Connection, project_nodes: GeoDataFrame, project_links: GeoDataFrame, project_zones: GeoDataFrame, modes: list[str], k_connectors: int = 1, limit_to_zone: bool = True, distance_upper_bound: float = inf, projected_crs: str | int | None = None)[source]#

Creates or updates centroid connectors between zone centroids and network nodes.

This function generates k-nearest neighbour connections from each zone centroid to nearby network nodes that support the specified transport modes. It can either limit connections to nodes within the same zone or find the globally nearest nodes.

Arguments:

conn (Connection): Database connection for executing SQL operations.

project_nodes (gpd.GeoDataFrame): GeoDataFrame containing network nodes with columns including node_id, is_centroid, modes, and geometry.

project_links (gpd.GeoDataFrame): GeoDataFrame containing network links with columns including link_id, a_node, b_node, modes, direction, and link_type.

project_zones (gpd.GeoDataFrame): GeoDataFrame containing zone polygons with columns including zone_id and geometry.

modes (list[str]): List of transport mode strings to create connectors for.

k_connectors (int, Optional): Number of nearest neighbour connections to create per centroid. Defaults to 1.

limit_to_zone (bool, Optional): If True, only connects to nodes within the same zone. If False, finds globally nearest nodes. Defaults to True.

distance_upper_bound (float, Optional): Maximum distance for connections. Defaults to infinity.

projected_crs (str | int, Optional): Coordinate reference system for distance calculations. If None, uses the CRS from the input data.

aequilibrae.project.network.connector_creation.connector_creation(zone_id: int, mode_id: str, network, proj_nodes, proj_links, link_types='', connectors=1, conn: Connection | None = None, delimiting_area: Polygon | None = None)[source]#
aequilibrae.project.network.connector_creation.k_nearest(k: int, centroids: GeoDataFrame, nodes: GeoDataFrame, distance_upper_bound: float, crs: int | str)[source]#

Finds the k nearest nodes to each centroid using a KDTree spatial index.

Arguments:

k (int): Number of nearest neighbours to find for each centroid.

centroids (gpd.GeoDataFrame): GeoDataFrame containing centroid points with node_id and geometry columns.

nodes (gpd.GeoDataFrame): GeoDataFrame containing network nodes with node_id and geometry columns to search within.

distance_upper_bound (float): Maximum distance for neighbour search.

crs (int | str): Coordinate reference system for distance calculations.

Returns:

pd.DataFrame: DataFrame with columns a_node (centroid), b_node (nearest node), and distance, sorted by a_node and distance.

aequilibrae.project.network.connector_creation.k_nearest_in_zone(k: int, zones: GeoDataFrame, centroids: GeoDataFrame, nodes: GeoDataFrame, distance_upper_bound: float, crs: int | str)[source]#

Finds the k nearest nodes within each zone to the corresponding centroid.

Uses spatial indexing to first determine which nodes fall within each zone, then calculates distances only between centroids and nodes in the same zone.

Arguments:

k (int): Number of nearest neighbours to find for each centroid.

zones (gpd.GeoDataFrame): GeoDataFrame containing zone polygons with zone_id and geometry columns.

centroids (gpd.GeoDataFrame): GeoDataFrame containing centroid points with node_id and geometry columns, corresponding to zones.

nodes (gpd.GeoDataFrame): GeoDataFrame containing network nodes with node_id and geometry columns to search within.

distance_upper_bound (float): Maximum distance for neighbour search.

crs (int | str): Coordinate reference system for distance calculations.

Returns:

pd.DataFrame: DataFrame with columns a_node (centroid), b_node (nearest node), and distance, limited to k nearest nodes per centroid within the same zone.

aequilibrae.project.network.connector_creation.normalise_mode_strings(x)[source]#

Normalises a collection of mode strings by sorting unique characters.

Takes a sequence of mode strings and returns a single string containing unique characters sorted alphabetically.

Arguments:

x (Iterable[str]): Collection of mode strings to normalise.

Returns:

str: Normalised string with unique characters sorted alphabetically.