UrbanAccessAnalyzer.csr_network¶
Street network -> CSR graph, point snapping, and the edge <-> H3 cell records used by fast multi-source searches.
CsrNetwork takes the node/edge tables of a StreetNetwork (projected metres; StreetNetwork.save folders load with CsrNetwork.load, read-only) and gives
* indptr / adj / w undirected CSR graph (float32 metres), ready for compiled searches (transitlos.flex.core.multilabel_search),
* snap(lat, lon) each point becomes two sources: the two ends of the nearest edge, offset by the snap distance plus the position along the edge
(what splitting the edge at the point would give),
* edge_cell_records(res) for every H3 cell the streets touch, the edges that touch it with the stretch [a, b] of each edge inside the cell. The
distance until an edge touches a cell is then min(d_u + a, d_v + L - b) over those edges (+ the cell radius, added by the caller).
A station is snapped to the nearest point of the nearest edge and becomes two sources (the two edge ends, offset by the snap distance plus the
position along the edge), which is what splitting the edge at the stop would give. A cell's distance is the distance until an edge touches it
(entry/exit positions of the edge inside the cell) + the cell radius (added in core.process_cells).
CsrNetwork(nodes, edges, crs)
¶
A street network in compressed sparse row form, for fast shortest-path searches from many stations at once.
Built from node and edge tables (node_id; u, v, length_m); edges are made undirected and unique.
load(folder)
classmethod
¶
Load a network saved as nodes.parquet, edges.parquet and meta.txt (the CRS) in folder.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
folder
|
The network folder. |
required |
Returns:
| Type | Description |
|---|---|
'CsrNetwork'
|
The network. |
snap(lat, lon, max_snap_m=300.0)
¶
Sources for stations at (lat, lon): returns (src_node, src_off, src_station, snapped_mask).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lat
|
Station latitudes (EPSG:4326). |
required | |
lon
|
Station longitudes (EPSG:4326). |
required | |
max_snap_m
|
float
|
Stations farther than this from every edge are not snapped. |
300.0
|
Returns:
| Type | Description |
|---|---|
|
|
|
|
walking distance from the station to each, the station index of each source, and which stations were |
|
|
snapped. |
edge_cell_records(resolution=10, edge_mask=None)
¶
Records of (cell, edge, entry a, exit b): cells = uint64 H3 ids, sorted by cell. Returns (cells_unique, rec_off, ru, rv, ra, rb, rl).
edge_mask (bool per undirected edge, e.g. "an end of the edge was reached by the search") restricts the work to those edges: rural networks have
millions of edges nobody can reach.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
resolution
|
int
|
H3 resolution of the cells. |
10
|
edge_mask
|
Optional boolean per undirected edge: only those edges are sampled. |
None
|