Skip to content

Analyzing Spatial Demand using Mapping

Harsha Ramachandran edited this page Jul 27, 2022 · 6 revisions

From the Estimating Demand and Supply at Different Time Intervals section we have a DataFrame containing information on the bike station locations and their average demand/supply value at the end of a week and at the end of a day. We can use maps to visualize how the demand and supply varies across London and get useful insights.

Initializing the base map

We use Folium, a python library for mapping and visualizations. We first initialize a base map of London to use to later visualize the demand data.

map = folium.Map(location = [51.5073219, -0.1276474], tiles='cartodbdark_matter' , zoom_start = 13 )

This creates a base map for us to visualize the demand/supply data on.

london-base-map

Visualization with Cluster Mapping

We will use Folium's cluster mapping plugin to visualize the demand and supply at different bike stations. Cluster Mappers groups different points into clusters depending on their location and the zoom level of the map. By plotting each demand/supply as one unit at a particular bike station, we can view how the demand varies across the map.


To start we create two Feature Groups called demand and supply. These groups will allow us to later toggle viewing demand and supply on the map. We add two MarkerCluster objects to each feature group.

fg_supply = folium.FeatureGroup(name = "Supply", show = True)
fg_demand = folium.FeatureGroup(name = "Demand", show = False)
marker_cluster = MarkerCluster().add_to(fg_demand)
marker_cluster2 = MarkerCluster().add_to(fg_supply)

Next we iterate through each of the BikeStations and convert the demand value to an Integer. We also set a boolean variable to True or False depending on whether the BikeStation has demand (>0) or supply (<0).

for x in bikeStations.index:
        demand = bikeStations['demand'][x]
        supply = False
        if demand>0:
            demand = math.floor(demand)
        else:
            demand = abs(math.ceil(demand))
            supply=True

Finally we add a n markers to each BikeStation on the map, where n is the demand/supply. If the supply boolean variable is true we add the marker to the supply marker cluster and vice versa for demand.

if supply:
            for _ in range(1,demand +1):
                folium.Marker(
                location=[bikeStations['lat'][x], bikeStations['lon'][x]],
                popup=bikeStations['demand'][x],
                icon=folium.Icon(color='green', prefix='fa',icon='bicycle')
                ).add_to(marker_cluster2)
            
        else:
            for _ in range(1,demand +1):
                folium.Marker(
                location=[bikeStations['lat'][x], bikeStations['lon'][x]],
                popup=bikeStations['demand'][x],
                icon=folium.Icon(color='red', prefix='fa',icon='bicycle')
                ).add_to(marker_cluster)

Map Demonstration

The resultant map allows us to view both the demand and supply by toggling the relevant settings. It also groups the values into clusters and displays the number of excess/demand for bikes in said cluster. We can zoom in to break up the clusters and click on particular clusters to view the number of bikes there.

map-demonstration

Spatial Analysis

We now have maps with data for visualizing supply and demand at the end of a day and at the end of the week. Lets first take a look at the daily maps.

Daily Demand/Supply

Daily Demand

Daily-Demand

Daily Supply

Daily-Supply

Daily Heat Map (Red - Demand, Green - Supply)

Daily-HeatMap

We see that there seems to be more demand outside of the 'central' London, around Westminster in this case. And there is quite a large amount of corresponding supply near the center of London along the Thames. What this suggests is that there are more Bike trips into central London than there are Bike trips out of it. However the daily data is rather limited by the fewer number of bikes. Lets take at the average demand and supply at the end of the week to try and see if these trends still hold.

Weekly Supply/Demand

Weekly Supply

Weekly-Supply

Weekly Demand

Weekly-Demand

Weekly Heat Map (Red - Demand, Green - Supply)

Weekly-HeatMap

The weekly maps follow the same trend, but they give us much more information on spread of demand and supply. As can be seen the supply is still most heavily concentrated around the center of London, these central areas are Soho, Westminster and near Whitechapel/London Bridge. Unlike the previous daily values, that the demand is more spread out than suggested by the daily values. The highest concentration of demand is in the Bayswater and Hoxton areas. However we can observe demand in areas all around London, in particular, the demand seems to form a circle around the central areas of high supply as mentioned above. This supports the hypothesis that the bikes tend to move from outside London into the center.