blocksnet.preprocessing.accessibility_processor

Module used to generate graph based on user territory and calculate the accessibility matrix.

Classes

AccessibilityProcessor(blocks)

Processor class for calculating accessibility matrix and generating intermodal graph for a given set of city blocks.

BlocksSchema(*args, **kwargs)

Schema class for handling geospatial block data with specified geometry types.

class blocksnet.preprocessing.accessibility_processor.BlocksSchema(*args, **kwargs)[source]

Bases: BaseSchema

Schema class for handling geospatial block data with specified geometry types.

Variables:

_geom_types (list) – List of allowed geometry types (Polygon, MultiPolygon).

class Config

Bases: Config

name = 'BlocksSchema'
class blocksnet.preprocessing.accessibility_processor.AccessibilityProcessor(blocks: GeoDataFrame)[source]

Bases: object

Processor class for calculating accessibility matrix and generating intermodal graph for a given set of city blocks.

Parameters:

blocks (gpd.GeoDataFrame) – A GeoDataFrame containing the geospatial data of city blocks.

property polygon: Polygon

Computes the convex hull polygon that encloses all blocks.

Returns:

Convex hull of the blocks in the specified CRS (IDUEDU_CRS).

Return type:

shapely.geometry.Polygon

static plot(blocks: GeoDataFrame, graph: Graph, figsize: tuple[int, int] = (10, 10), linewidth: float = 0.2)[source]

Plots the urban blocks and the intermodal city graph on a map.

Parameters:
  • blocks (gpd.GeoDataFrame) – GeoDataFrame containing the urban blocks geometry.

  • graph (nx.Graph) – NetworkX graph representing the intermodal transportation network.

  • figsize (tuple[int, int], optional) – Size of the figure (width, height), by default (10, 10).

  • linewidth (float, optional) – Width of the plotted edges, by default 0.2.

static _get_broken_nodes(graph: Graph) list[source]

Identifies broken nodes in the graph that do not have ‘x’ or ‘y’ coordinates.

Parameters:

graph (nx.Graph) – NetworkX graph representing the transportation network.

Returns:

A list of broken node identifiers.

Return type:

list

classmethod _fix_graph(graph) None[source]

Removes broken nodes from the graph that do not have valid coordinates inplace.

Parameters:

graph (nx.Graph) – NetworkX graph representing the transportation network.

get_intermodal_graph(clip_by_bounds: bool = True, keep_routes_geom: bool = True) Graph[source]

Generates an intermodal transportation graph for the given blocks area.

Parameters:
  • clip_by_bounds (bool, optional) – Whether to clip the graph by the polygon bounds, by default True.

  • keep_routes_geom (bool, optional) – Whether to keep the geometry of the routes in the graph, by default True.

Returns:

NetworkX graph representing the intermodal transportation network.

Return type:

nx.Graph

get_accessibility_matrix(graph: Graph, weight: str = 'time_min') DataFrame[source]

Calculates the accessibility matrix between city blocks using the provided graph.

Parameters:
  • graph (nx.Graph) – NetworkX graph representing the intermodal transportation network.

  • weight (str, optional) – Edge attribute to use for calculating distances (e.g., ‘time_min’), by default “time_min”.

Returns:

Accessibility matrix as a DataFrame.

Return type:

pd.DataFrame