Quantifying Walkability: Measuring Network Length
One of the fundamental aspects of walkability is the physical length of pedestrian pathways within a city. In this section, we introduce a function that calculates and quantifies the total length of the pedestrian network in kilometers.
Measuring Network Length
The following Python function, get_network_length_km(graph), takes the extracted pedestrian network graph (graph) as input and computes the total length of network edges in kilometers. Let's break down the code:
# Compute the total length of network edges in kmeters def get_network_length_km(graph): # Initialize variables to store total length total_length_meters = 0.0 # Calculate the total length of network edges in meters for u, v, data in graph.edges(data=True): if 'length' in data: # Check if 'length' attribute exists total_length_meters += data['length'] # Convert to kilometers total_length_km = total_length_meters / 1000 # Print the total length in kilometers print(f"Total length of network edges (km): {total_length_km}") return total_length_km
G_total_length_km=get_network_length_km(G)
Total length of network edges (km): 27186.319582000375
Understanding the Function
1. Initialization: The function starts by initializing a variable (total_length_meters)
to store the cumulative length of all network edges.
2. Calculating Length: It then iterates through each edge in the network, checking if the 'length' attribute exists
in the edge data. If so, it adds the length to the total.
3. Conversion: The total length is initially measured in meters and is then converted to kilometers.
4. Print and Return: Finally, the function prints the total length in kilometers
and returns this value for further analysis.
Application in Walkability Analysis
Measuring the network length is a critical step in understanding the extent of walkable pathways within the city.