polaris.network.traffic.intersec.Intersection#

class polaris.network.traffic.intersec.Intersection(data_tables, path_to_file: PathLike, conn: Connection | None = None, osm: OSM | None = None)#

Bases: object

Network intersection class

from polaris.network.network import Network

net = Network()
net.open('D:/Argonne/GTFS/CHICAGO/chicago2018-Supply.sqlite')

curr = net.conn.cursor()
curr.execute('SELECT node FROM Node order by node')


for node in nodes:
    intersection = net.get_intersection(node)

    # To rebuild the intersection checking OSM, one can just do this
    intersection.rebuild_intersection(check_type='osm'):

    # Or one can do each step to be able to manipulate the signal as they go
    intersection.rebuild_connections()
    if intersection.osm_signal():
    # if intersection.determine_geometric_need_for_signal()
        if not intersection.supports_signal():
            print(f'Node {node} does not support a signal. Skipping it')
            continue
        sig = intersection.create_signal()
        # Here you can manipulate the signal
        sig.re_compute()
        # Or after recomputing as well
        sig.save()
__init__(data_tables, path_to_file: PathLike, conn: Connection | None = None, osm: OSM | None = None)#

Methods

__init__(data_tables, path_to_file[, conn, osm])

add_movement(from_link, to_link, conn[, note])

Allows a movement by inserting it in the Turn_Overrides table with a penalty of 0

add_stop_sign(conn)

Adds a stop sign to this intersection

allow_pockets_for_all()

Allows all approximations for this intersection to have pockets created for them

allowed_turns()

Returns a list of all link pairs allowed for convergence in this node

block_movement(from_link, to_link, conn)

Blocks a movement by inserting it in the Turn_Overrides table with a penalty of -1

block_pockets_for_all()

Blocks all approximations for this intersection to have pockets created for them

connections(conn)

create_signal(conn[, compute_and_save])

Returns a traffic signal object for this intersection

delete_signal(conn)

Deletes the signal for this intersection

delete_stop_sign(conn)

Deletes the signal for this intersection

determine_geometric_need_for_signal(conn)

Determines if a signal is needed based on intersection geometry, link types and area type

has_signal(conn)

Checks if there is a signal for this intersection

has_stop_sign(conn)

Checks if there is a signal for this intersection

links(conn)

load(node[, conn])

Loads the intersection object for the provided node

osm_signal([buffer, re_check, return_when_fail])

We check Open-Streets Map for a traffic light in this vicinity

rebuild_connections([clear_it_first, conn])

Rebuilds all connections for the intersection

rebuild_intersection(conn[, signal_type, ...])

Rebuilds an entire intersection

save_pockets(conn)

supports_signal(conn)

If this intersection geometrically supports a signal (does it make sense)

Attributes

__init__(data_tables, path_to_file: PathLike, conn: Connection | None = None, osm: OSM | None = None)#
load(node: int, conn: Connection | None = None) None#

Loads the intersection object for the provided node

Args:

node (int): Node ID to load as an intersection

allow_pockets_for_all() None#

Allows all approximations for this intersection to have pockets created for them

Default permissions for pocket creation are extracted from the Link_Type table. For more information go to the table documentation

block_pockets_for_all() None#

Blocks all approximations for this intersection to have pockets created for them

Default permissions for pocket creation are extracted from the Link_Type table. For more information go to the table documentation

rebuild_intersection(conn: Connection, signal_type='keep_existing', clear_it_first=True)#

Rebuilds an entire intersection

Removes connections and traffic signals before rebuilding connections and (optionally) signals

Args:

signal_type (str, Optional): Type of check to determine if a signal should be added. Defaults to keeping existing intersection control type

check_type
  • ‘geometric’: Determines need for signal based on the intersection geometry

  • ‘osm’: Determines need for signal based on the existence of such on OSM

  • ‘forced’: Forces the placement of a signal

  • ‘stop_sign’: Places stop signs in the intersection only

  • ‘none’: Does not place any type of intersection control on this intersection

  • ‘keep_existing’: Keeps the intersection control currently in place for the intersection

add_stop_sign(conn: Connection)#

Adds a stop sign to this intersection

rebuild_connections(clear_it_first=True, conn: Connection | None = None) None#

Rebuilds all connections for the intersection

Removes any pre-existing connections and traffic signal for this intersection

Args:

clear_it_first (bool, Optional): Whether to clear existing connections, pockets and signals It allows faster processing if no prior clearing is needed, but it will fail if connections and pockets data still exist for this node. Defaults to True

block_movement(from_link: int, to_link: int, conn: Connection) None#

Blocks a movement by inserting it in the Turn_Overrides table with a penalty of -1

It also recomputes the signal in the intersection in case there is a signal to be re-computed

Args:

from_link (int): Origin link for the allowed turn to_link (int): Destination link for the allowed turn

add_movement(from_link: int, to_link: int, conn: Connection, note='') None#

Allows a movement by inserting it in the Turn_Overrides table with a penalty of 0

Args:

from_link (int): Origin link for the allowed turn to_link (int): Destination link for the allowed turn note (str): Any notes that should be added to the Turn_Overrides table

osm_signal(buffer=30, re_check=False, return_when_fail=False) bool#

We check Open-Streets Map for a traffic light in this vicinity

Before making the first call to this function, it is recommended deploying your own OSM Overpass server and set IP and sleep time appropriately. See the OSM module documentation for more details

Args:

buffer (int, Optional): Distance between node and OSM signal to be considered same point. Defaults to 30m

re_check (bool, Optional): To check again for a different buffer, set it to True. Defaults to False

return_when_fail (bool, Optional): Value to return when the OSM query fails.

# Here we default to our own server
osm = net.osm
osm.url = 'http://192.168.0.105:12345/api'
osm.sleep_time = 0
has_signal(conn: Connection) bool#

Checks if there is a signal for this intersection

has_stop_sign(conn: Connection) bool#

Checks if there is a signal for this intersection

delete_stop_sign(conn: Connection)#

Deletes the signal for this intersection

delete_signal(conn: Connection)#

Deletes the signal for this intersection

create_signal(conn: Connection, compute_and_save=True) Signal | None#

Returns a traffic signal object for this intersection

Return:

signal (Signal): Traffic signal object

supports_signal(conn: Connection) bool#

If this intersection geometrically supports a signal (does it make sense)

Return:

support (True): Boolean for it a signal can be configured for this intersection

determine_geometric_need_for_signal(conn: Connection) bool#

Determines if a signal is needed based on intersection geometry, link types and area type

It is somewhat similar to the capability from TranSims

allowed_turns() List[List[int]]#

Returns a list of all link pairs allowed for convergence in this node

property connection_data_records#
save_pockets(conn: Connection)#
connections(conn: Connection)#