transport_frames.road_adder
Module for adding new roads to the graph
Functions
|
Adds new roads to the city graph by processing each line in the road GeoDataFrame. |
|
Connect a line to nearby roads by adding nodes and edges as needed. |
Generate a new unique node ID. |
|
|
Find the node corresponding to a LineString end using the nearest node. |
|
Find the nearest node within a specified buffer distance. |
|
Find the nearest road and the closest point on that road within a specified buffer distance. |
|
Create a GeoDataFrame with edge data based on geometry and other attributes. |
|
Create a GeoDataFrame with node data based on geometry and other attributes. |
|
Modifies the city graph by removing edges and adding new nodes and edges. |
|
Splits roads at intersection points and adds nodes and edges for new road segments. |
- transport_frames.road_adder.create_nodeID() int [source]
Generate a new unique node ID.
- Returns:
The new node ID.
- Return type:
int
- transport_frames.road_adder.find_nearest_node(point: Point, nodes_gdf: GeoDataFrame, node_buffer: float) int [source]
Find the nearest node within a specified buffer distance.
- Parameters:
point (Point) – The point to find the nearest node for.
nodes_gdf (gpd.GeoDataFrame) – GeoDataFrame containing nodes.
node_buffer (float) – The buffer distance within which to search for the nearest node.
- Returns:
The ID of the nearest node, or None if no node is found.
- Return type:
int
- transport_frames.road_adder.find_nearest_road_point(point: Point, roads_gdf: GeoDataFrame, road_buffer: float) tuple [source]
Find the nearest road and the closest point on that road within a specified buffer distance.
- Parameters:
point (Point) – The point to find the nearest road for.
roads_gdf (gpd.GeoDataFrame) – GeoDataFrame containing roads.
road_buffer (float) – The buffer distance within which to search for the nearest road.
- Returns:
A tuple containing the nearest roads GeoDataFrame and the nearest point on the road, or (None, None) if no road is found.
- Return type:
tuple
- transport_frames.road_adder.make_edge_data(edge_geom: LineString, maxspeed: float, reg: int, local_crs: str, start: int | None = None, end: int | None = None, nodes_gdf: GeoDataFrame | None = None, bidirectional: bool = True, flag: str | None = None) GeoDataFrame [source]
Create a GeoDataFrame with edge data based on geometry and other attributes.
- Parameters:
edge_geom (LineString) – The geometry of the edge.
maxspeed (float) – The maximum speed on the edge.
reg (int) – The region identifier.
local_crs (str) – The coordinate reference system.
start (int, optional) – The starting node ID. Defaults to None.
end (int, optional) – The ending node ID. Defaults to None.
nodes_gdf (gpd.GeoDataFrame, optional) – GeoDataFrame of nodes. Defaults to None.
bidirectional (bool, optional) – If True, creates a bidirectional edge. Defaults to True.
flag (str, optional) – Additional information for the edge. Defaults to None.
- Returns:
A GeoDataFrame containing the edge data.
- Return type:
gpd.GeoDataFrame
- transport_frames.road_adder.make_node_data(point: Point, local_crs: int, reg_1: bool = False, reg_2: bool = False, flag: str = 'intersection') GeoDataFrame [source]
Create a GeoDataFrame with node data based on geometry and other attributes.
- Parameters:
point (Point) – The geometry of the node.
local_crs (str) – The coordinate reference system.
reg_1 (bool, optional) – Indicator for region 1. Defaults to False.
reg_2 (bool, optional) – Indicator for region 2. Defaults to False.
exit (str, optional) – Exit status. Defaults to ‘RECOUNT’.
exit_country (str, optional) – Exit country. Defaults to ‘RECOUNT’.
flag (str, optional) – Additional information for the node. Defaults to ‘intersection’.
- Returns:
A GeoDataFrame containing the node data.
- Return type:
gpd.GeoDataFrame
- transport_frames.road_adder.find_end_node(end: tuple, nodes_gdf: GeoDataFrame, local_crs: int) GeoDataFrame [source]
Find the node corresponding to a LineString end using the nearest node.
- Parameters:
end (tuple) – The coordinates of the end point.
nodes_gdf (gpd.GeoDataFrame) – GeoDataFrame containing nodes.
local_crs (int) – The coordinate reference system.
- Returns:
The nearest node as a GeoDataFrame.
- Return type:
gpd.GeoDataFrame
- transport_frames.road_adder.connect_line_to_roads(each_line: GeoSeries, nodes_gdf: GeoDataFrame, edges_gdf: GeoDataFrame, node_buffer: float, edge_buffer: float, local_crs: str) tuple [source]
Connect a line to nearby roads by adding nodes and edges as needed.
- Parameters:
each_line (gpd.GeoSeries) – The line to connect.
nodes_gdf (gpd.GeoDataFrame) – GeoDataFrame containing existing nodes.
edges_gdf (gpd.GeoDataFrame) – GeoDataFrame containing existing edges.
node_buffer (float) – Buffer distance to search for existing nodes.
edge_buffer (float) – Buffer distance to search for existing edges.
local_crs (int) – The coordinate reference system.
- Returns:
A tuple containing GeoDataFrames of added nodes, added edges, a list of deleted edges, and a list of deleted edge ends.
- Return type:
tuple
- transport_frames.road_adder.split_roads(each_line: GeoDataFrame, intermediate_nodes: GeoDataFrame, intermediate_edges: GeoDataFrame, local_crs: str) tuple [source]
Splits roads at intersection points and adds nodes and edges for new road segments.
- Parameters:
each_line (gpd.GeoDataFrame) – The new road geometry being processed.
intermediate_nodes (gpd.GeoDataFrame) – GeoDataFrame of nodes for the existing road network.
intermediate_edges (gpd.GeoDataFrame) – GeoDataFrame of edges for the existing road network.
local_crs (str) – Coordinate reference system for spatial data.
- Returns:
- A tuple containing:
added_intersections_nodes (gpd.GeoDataFrame): GeoDataFrame of new intersection nodes.
added_intersections_edges (gpd.GeoDataFrame): GeoDataFrame of new road segments.
del_list (list): List of indices of deleted roads.
del_list_ends (list): List of node start-end pairs of deleted roads.
- Return type:
tuple
- transport_frames.road_adder.modify_graph(citygraph: MultiDiGraph, del_list_ends: list, nodes_to_add: GeoDataFrame, edges_to_add: GeoDataFrame) Graph [source]
Modifies the city graph by removing edges and adding new nodes and edges.
- Parameters:
citygraph (nx.MultiDiGraph) – The existing city graph.
del_list_ends (list) – List of node start-end pairs for edges to remove.
nodes_to_add (gpd.GeoDataFrame) – GeoDataFrame of nodes to add to the graph.
edges_to_add (gpd.GeoDataFrame) – GeoDataFrame of edges to add to the graph.
- Returns:
The modified city graph.
- Return type:
nx.Graph
- transport_frames.road_adder.add_roads(citygraph: MultiDiGraph, line_gdf: GeoDataFrame, local_crs: int, node_buffer: int = 300, road_buffer: int = 5000) Graph [source]
Adds new roads to the city graph by processing each line in the road GeoDataFrame.
- Parameters:
citygraph (nx.MultiDiGraph) – The existing city graph.
line_gdf (gpd.GeoDataFrame) – GeoDataFrame of the new road lines.
nodes_gdf (gpd.GeoDataFrame) – GeoDataFrame of the existing road network nodes.
edges_gdf (gpd.GeoDataFrame) – GeoDataFrame of the existing road network edges.
local_crs (int) – Coordinate reference system for spatial data.
node_buffer (int) – Buffer distance for finding nearby nodes. Defaults to 300.
road_buffer (int) – Buffer distance for finding nearby roads. Defaults to 5000.
- Returns:
The modified city graph with new roads, nodes, and edges.
- Return type:
nx.MultiDiGraph