<jupyter_start><jupyter_text>Getting the data `osmnx` goes to OpenStreetMaps API and request the `.osm` file and parse it, but as you remember from our discussion in the README that not all nodes are grouped properly in OpenStreetMaps and we end up with multiple connected components in the same area when it should have been complete, although maybe our scope is small to give us all the nodes so some ways/relation are destructed. `osmnx` default behavior is to give you back the biggest component in that area and that is it, we will turn that option off. **1. Turning textual representation of a location to a graph**  Using [`osmnx.graph.graph_from_address`](https://osmnx.readthedocs.io/en/stable/osmnx.htmlosmnx.graph.graph_from_address)<jupyter_code># see how we give informal address to the API
# if you can enter the address in OpenStreetMaps and find it
# osmnx will find it -- they both use Nominatim for geodecoding
G = ox.graph_from_address(address = "east harbour toronto", dist = 700, retain_all = True)
len(G)
fig, ax = ox.plot_graph(G)<jupyter_output><empty_output><jupyter_text>we have "10" networkx in our graph<jupyter_code>nx.number_strongly_connected_components(G)<jupyter_output><empty_output><jupyter_text>In that case we go to use [OSRM](http://project-osrm.org/) to find the routes and use ipyleaflet or folium or our wrapper to see that route, it will be much clearer when we start doing case studies. **2- Bounding box around some area**  Using [`osmnx.graph_from_bbox`](https://osmnx.readthedocs.io/en/stable/osmnx.htmlosmnx.graph.graph_from_bbox) bbox stands for bounding box and is formed from four number  (northern latitude of bounding box,  southern latitude of bounding box,  eastern longitude of bounding box,   western longitude of bounding box)<jupyter_code>G = ox.graph_from_bbox(-37.7860, -37.8359, 144.9903, 144.9269 , retain_all = True)
fig, ax = ox.plot_graph(G)
len(G)<jupyter_output><empty_output><jupyter_text>**3- From `osm` file**  Using [`osmnx.graph_from_xml`](https://osmnx.readthedocs.io/en/stable/osmnx.htmlosmnx.graph.graph_from_xml) We will get into OverPass API and how to use its query language in Open-Datasets repositories but take it as it is for now. The following OverPass QL generated the `.osm` file we will import its data    ```  (  node(50.746,7.154,50.748,7.157);  <;  >;);out meta;  ```<jupyter_code>G = ox.graph_from_xml("./data/data1.osm", retain_all = True)
fig, ax = ox.plot_graph(G)<jupyter_output><empty_output><jupyter_text>Stats about the map<jupyter_code>ox.basic_stats(G)
ox.extended_stats(G,connectivity = True, ecc = True, bc=True, cc=True) # there is other options<jupyter_output><empty_output><jupyter_text>The above dictionary is huge but I want to point out `center`, `diameter` fields in the above dict because it's super beneficial to know them in some situations<jupyter_code>ox.extended_stats(G,connectivity = True, ecc = True, bc=True, cc=True)['center']
ox.extended_stats(G,connectivity = True, ecc = True, bc=True, cc=True)['diameter']<jupyter_output><empty_output><jupyter_text>Getting **geopandas** data frames to have a data structure representing the nodes and the ways in the graph, this is super important.<jupyter_code>nodes, ways =  ox.graph_to_gdfs(G)
nodes<jupyter_output><empty_output><jupyter_text>Select the data of one row<jupyter_code>nodes.loc[31941906] #this acts as dictionary to access the inner variables
ways<jupyter_output><empty_output><jupyter_text>These are all the ways between the nodes  let's draw the geometry of one and see the relevance between it and between the actual map<jupyter_code>ways.loc[4]
ways.loc[4]['geometry']
highlighted = [69291476, 69291487]
nc = ['r' if node in highlighted else '#336699' for node in G.nodes()]
ns = [50 if node in highlighted else 8 for node in G.nodes()]
fig, ax = ox.plot_graph(G, node_size=ns, node_color=nc, node_zorder=2)<jupyter_output><empty_output><jupyter_text>This is how `osmnx` plot the route between incident nodes. If you went over to [overpass editor](http://overpass-turbo.eu/) and executed the OverPass QL script, you will find that this route has a lot of nodes that are not obvious in `osmnx` graph and seemed to be deleted from the file. That is right, `osmnx` parser after parsing all the nodes and put it according to ints coordinates on `matplotlib` plot, it will parse ways/relations which includes many nodes that dictate its shapes and curves. The parser will discard any node that is not the begining or ending of a way as it doesn't give us any thing except more memory and computation overhead. This can be turned of by `simplify` argument in all the getting data functions watch closely what would happen now<jupyter_code>G = ox.graph_from_xml("./data/data1.osm", retain_all = True, simplify = False)
fig, ax = ox.plot_graph(G)
G = ox.graph_from_xml("./data/data1.osm", retain_all = True, simplify = True) # the default behavior
fig, ax = ox.plot_graph(G)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09185929648241206, 'fraction_numerical': 0.01829145728643216, 'mean_word_length': 5.608233731739708, 'pattern_counts': {'":': 0, '<': 42, '<?xml version=': 0, '>': 42, 'https://': 3, 'lorem ipsum': 0, 'www.': 0, 'xml': 5}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '10', 'dir': 'jupyter-structured-clean-dedup', 'id': '632000', 'license': 'Apache-2.0', 'n_tokens_mistral': 1670, 'n_tokens_neox': 1570, 'n_words': 589, 'path': 'OGS.ipynb', 'repo_name': 'sierraone/GettingStarted', 'size': '4975'}