Skip to content

Analyzing Spatial Demand using Mapping

Harsha Ramachandran edited this page Jul 15, 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

Clone this wiki locally