instances.city_graph¶
-
instances.city_graph(city, G=None, k=None, seed=None, request_nodes=None)[source]¶ Generate an OSMnx graph of city.
PDP graph contains k request pairs and an s and t node selected randomly from original OSMnx graph through the seed parameter.
Parameters: - city (str) – The city to query road network from. ‘City, Country’.
- k (int) – 2 k + 2 is the number of nodes in graph.
If
None, default is 3 request pairs. - seed (int) – Seed for random graph generator. System time taken as default. H will always be the same, provided same G or city graph, k, and seed parameters.
- request_nodes (list) – k + 1 pairs of origin-destination elements to include from G in H. (s, t) pair is 0th term and (o_i, d_i) pairs are remaining origin-destination pairs.
Returns: - G (graph) – OSMnx generated input graph of city.
- H (graph) – Request graph version of G.
Examples
Query a city’s graph and make request graph a subgraph on 3 random request pairs set by the input seed.
>>> G, H = city_graph('Manhattan, USA', k=3, seed=23451)
Can also supply OSMnx graph G as a parameter in the case certain modifications were made by the user.
>>> import osmnx as ox >>> G = ox.graph_from_place('Cornell University, USA', network_type='drive') >>> G, H = city_graph('Cornell University, USA', G=G, k=5)