iduedu.nearest_objects

iduedu.nearest_objects(urban_graph, *, gdf_origins=None, gdf_objects=None, origins_nodes=None, object_nodes=None, k=1, cutoff=None, weight='time_min', direction='from', graph_node_column='graph_node_id', max_workers=None)[source]

Find the k nearest objects of every origin along the network.

Each origin runs one search that stops as soon as k objects are found, so the cost does not grow with the number of objects.

Parameters:
  • urban_graph (UrbanGraph) – Graph to search.

  • gdf_origins (DataFrame | None) – Origin objects, with graph_node_column or matched to their nearest nodes, or

  • origins_nodes (Optional[Iterable[Any]]) – origin node ids.

  • gdf_objects (DataFrame | None) – Objects to look for, with the same conventions, or

  • object_nodes (Optional[Iterable[Any]]) – their node ids.

  • k (int) – Number of objects to return per origin.

  • cutoff (float | None) – Largest travel cost, inclusive; None for no limit.

  • weight (Literal['length_meter', 'time_min']) – Edge cost column: time_min (minutes) or length_meter (metres).

  • direction (Literal['from', 'to']) – "from" measures the way from the origin to the object, "to" from the object to the origin. They differ on directed graphs.

  • graph_node_column (str) – Column of object tables that holds graph node ids.

  • max_workers (int | None) – Number of threads; None uses all cores.

Return type:

DataFrame

Returns:

DataFrame with a (origin, rank) MultiIndex (rank starts at 1) and columns object (label of the object in its table, or its node id) and dist. Origins with fewer than k reachable objects have fewer rows; objects on the same node keep the order of the object table.

Raises:

ValueError – If k is not a positive integer, or inputs cannot be resolved to graph nodes.