Skip to content

Instantly share code, notes, and snippets.

@SebastianoF
Last active April 24, 2022 15:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SebastianoF/fe2d8bc4188ebe63a653d1a80a7fcce8 to your computer and use it in GitHub Desktop.
Save SebastianoF/fe2d8bc4188ebe63a653d1a80a7fcce8 to your computer and use it in GitHub Desktop.
b001_11.py
# -- St Luke office
# narrow dataset to the geometry
mask_st_luke_office = gdf_commuters_workplace.intersects(shape(polygon_st_luke_office))
df_commuters_st_luke_office = df_commuter[mask_st_luke_office]
# embed shape into a geopandas to visualise in kepler
gdf_st_luke_geometry = gpd.GeoDataFrame({'geometry':[shape(polygon_st_luke_office)], "display_name": ["St Luke's Close Office"]})
# -- Same for Albert Road office
mask_albert_road = gdf_commuters_workplace.intersects(shape(polygon_albert_road))
df_commuters_albert_road = df_commuter[mask_albert_road]
gdf_albert_road = gpd.GeoDataFrame({'geometry':[shape(polygon_albert_road)], "display_name": ["St Luke's Close Office"]})
# --- Visualisation ---
try:
from kepler_config import config_map_4
except ImportError:
config_map_4 = config
map_4 = KeplerGl(
data={
"St Luke's Close Office": gdf_st_luke_geometry.copy(),
"commuters to St Luke": df_commuters_st_luke_office.copy(),
"Albert Road Office": gdf_albert_road.copy(),
"commuters to Albert": df_commuters_albert_road.copy(),
},
config=config_map_4,
height=800
)
display(map_4)
print(f"Commuters to St Luke office {len(df_commuters_st_luke_office)} ({100 * len(df_commuters_st_luke_office) / len(df_commuter)} %)" )
print(f"Commuters to Albert Road office {len(df_commuters_albert_road)} ({100 * len(df_commuters_albert_road) / len(df_commuter)} %)")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment