Openstreetmap point of interest data
Collecting and exploring different buildings from Openstreetmap
import pandas as pd
import geopandas as gpd
import osmnx as ox
import matplotlib.pyplot as plt
import contextily as cx
shop_types = pd.read_csv("../data/osm_shop_types.csv")
shop_types.shape
shop_types.head()
def plot_shops(place):
tags = {'building':True}
bds = ox.geometries_from_place(place, tags)
tags = {'amenity':True}
ams = ox.geometries_from_place(place, tags)
tags = {"shop":True}
shs = ox.geometries_from_place(place, tags)
f, ax = plt.subplots(1, figsize=(20, 20))
bds.plot(marker=1, color='black', ax=ax)
ams.plot(ax=ax, color='b', marker=1, alpha=0.7)
shs.plot(ax=ax, alpha=0.8, color='r', marker=1)
cx.add_basemap(ax, crs=bds.crs.to_string(), source=cx.providers.Stamen.TonerLite)
ax.set_axis_off()
plt.show()
place = "City of Monash, Victoria, Australia"
tags = {"shop":True, "opening_hours":"*"}
shops = ox.geometries_from_place(place, tags)
shops.shape
shops.shop.value_counts().head(50)
plc = "City of Monash, Victoria, Australia"
plot_shops(plc)
plc = "Melbourne District, Melbourne, City of Melbourne, Victoria, Australia"
plot_shops(plc)
place = "Victoria, Australia"
tags = {"shop":True, "opening_hours":"*"}
shops = ox.geometries_from_place(place, tags)
shops.shape
shops.shape, type(shops)
columns = ['unique_id',
'osmid',
'element_type',
'addr:city',
'addr:housenumber',
'addr:postcode',
'addr:state',
'addr:street',
'postal_code',
'name',
'opening_hours','opening_date',
'operator',
'phone',
'shop',
'source',
'building:levels',
'building',
'geometry', 'lat', 'long',
'brand', 'landuse','state',
'Key', 'Value', 'Group Name', 'Group'
]
shops[columns].head().T
shops.Group.value_counts()
shops[columns].to_file(f"../data/toronto/raw/all_shops_victoria_australia.geojson", driver='GeoJSON')
shops[shops.geometry.geom_type.isin(['Point'])].shop.value_counts().head(60)
plc = "Toronto, Golden Horseshoe, Ontario, Canada"
plot_shops(plc)
GTHA = {"Toronto":1, "Durham Region":2, "York Region":3, "Peel Region":4, "Halton Region":5, "Hamilton":6}
GTHA
for region, code in GTHA.items():
print(region, code)
plc = region + ", Golden Horseshoe, Ontario, Canada"
plot_shops(plc)
place = "Ontario, Canada"
tags = {"shop":True, "opening_hours":"*"}
can_shops = ox.geometries_from_place(place, tags)
can_shops.shape
columns = ['unique_id',
'osmid',
'element_type',
'addr:city',
'addr:housenumber',
'addr:postcode',
'addr:street',
'postal_code',
'name',
'opening_hours',
'operator',
'phone',
'shop',
'source',
'building:levels',
'building',
'geometry',
'brand', 'landuse','state',
'Key', 'Value', 'Group Name', 'Group'
]
can_shops[columns].to_file(f"../data/toronto/raw/all_shops_ontario_canada.geojson", driver='GeoJSON')
can_shops = can_shops.merge(shop_types, how="left", left_on="shop", right_on="Value")
can_shops.Group.value_counts()
shops.Group.value_counts()