<jupyter_start><jupyter_text>City street network orientationsThe present book demonstrates how to develop different wind rose maps for the cities .The first task is to install the packages which we would later call to perform different functions in the notebook.<jupyter_code>!pip install matplotlib
!pip install numpy
!pip install osmnx<jupyter_output><empty_output><jupyter_text>Import the necessary packagesTo perform the network analysis of different streets we import following packages :osmx - Python package that lets you download geospatial data from OpenStreetMap and model, project, visualize, and analyze real-world street networks and any other geospatial geometries.numpy - NumPy to perform comprehensive mathematical functions. matplotlib - To visualize the data<jupyter_code>import matplotlib.pyplot as plt
import numpy as np
import osmnx as ox

%matplotlib inline
ox.config(log_console=True)
weight_by_length = False

ox.__version__<jupyter_output><empty_output><jupyter_text>Defining the Areas of InterestHere we create a variable which can be string or structured dict, or a list of such strings/dicts , which we can later call in Open Street map to query and geocode.<jupyter_code># define the study sites as label : query
places = {
       # 'Boston'        : 'Boston, MA, USA',
    
    "Milano": "Milan, Lombardy, Italy",
    "Bologna" : "Bologna, Emilia-Romagna, Italy",
    "Verona" : "Verona, Veneto, Italy",
    "Venice": "Venice, Venezia, Veneto, Italy",
    "Naples": "Naples, Napoli, Campania, Italy",
    "Rome": "Rome, Roma Capitale, Lazio, Italy"
}
# verify OSMnx geocodes each query to what you expect (i.e., a [multi]polygon geometry)
gdf = ox.geocode_to_gdf(list(places.values()))
gdf<jupyter_output><empty_output><jupyter_text>Converting these street data into length<jupyter_code># create figure and axes
n = len(places)
ncols = int(np.ceil(np.sqrt(n)))
nrows = int(np.ceil(n / ncols))
figsize = (ncols * 5, nrows * 5)
fig, axes = plt.subplots(nrows, ncols, figsize=figsize, subplot_kw={"projection": "polar"})

# plot each city's polar histogram
for ax, place in zip(axes.flat, sorted(places.keys())):
    print(ox.utils.ts(), place)

    # get undirected graphs with edge bearing attributes
    G = ox.graph_from_place(place, network_type="drive")
    Gu = ox.add_edge_bearings(ox.get_undirected(G))
    fig, ax = ox.bearing.plot_orientation(Gu, ax=ax, title=place, area=True)

# add figure title and save image
suptitle_font = {
    "family": "DejaVu Sans",
    "fontsize": 60,
    "fontweight": "normal",
    "y": 1,
}
fig.suptitle("City Street Network Orientation", **suptitle_font)
fig.tight_layout()
fig.subplots_adjust(hspace=0.35)<jupyter_output><empty_output><jupyter_text>You can also calculate the orientation entropy of a spatial graph with the `ox.bearing.orientation_entropy` function.<jupyter_code>fig.savefig("  # insert the location you want to save the above image", facecolor="w", dpi=100, bbox_inches="tight")
plt.close()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1016949152542373, 'fraction_numerical': 0.0036556995679627785, 'mean_word_length': 5.3906581740976645, 'pattern_counts': {'":': 9, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '628303', 'license': 'MIT', 'n_tokens_mistral': 1003, 'n_tokens_neox': 947, 'n_words': 312, 'path': 'Trasportation Projects/Italian_Cities_street_network_orientations.ipynb', 'repo_name': 'krishnaduttPanchagnula/Python_projects', 'size': '3009'}