Created
April 24, 2022 14:49
-
-
Save SebastianoF/0a5115933ec4976ad98a9722fe8f5412 to your computer and use it in GitHub Desktop.
b001_09.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -- about 17 seconds -- | |
gdf_commuters_workplace = gpd.GeoDataFrame(df_commuter.copy(), geometry=gpd.points_from_xy(df_commuter.workplace_lng, df_commuter.workplace_lat)) | |
# -- about 120 seconds: points in polygon | |
mask_points_in_city = gdf_commuters_workplace.intersects(gdf.geometry.iloc[0]) | |
mask_points_in_london = gdf_commuters_workplace.intersects(gdf.geometry.iloc[1]) | |
num_total_rows = len(gdf_commuters_workplace) | |
num_rows_in_city = len(mask_points_in_city[mask_points_in_city == True]) | |
num_rows_in_london = len(mask_points_in_london[mask_points_in_london == True]) | |
print(f"Number of rows for offices in the city {num_rows_in_city} ({100 * num_rows_in_city / num_total_rows} %)") | |
print(f"Number of rows for offices in london {num_rows_in_london} ({100 * num_rows_in_london / num_total_rows} %)") | |
mask_union = mask_points_in_city | mask_points_in_london | |
num_rows_in_union = mask_union.sum() | |
print(f"Number of offices in the union of London and the City {num_rows_in_union} ({100 * num_rows_in_union / num_total_rows} %)") | |
# Sanity check | |
assert num_rows_in_union == num_rows_in_city + num_rows_in_london | |
df_commuter_london_office = df_commuter[mask_union] | |
df_commuter_london_office.reset_index(inplace=True, drop=True) | |
try: | |
from kepler_config import config_map_3 | |
except ImportError: | |
config_map_3 = config | |
# Use the config_3 in kepler_config.py in the repo to reproduce the same image | |
map_3 = KeplerGl(data={'london':gdf_epsg.copy(), "commuters": df_commuter_london_office.copy()}, config=config_map_3, height=800) | |
display(map_3) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment