In [ ]:
%load_ext autoreload
%autoreload 2
import pandas as pd
import numpy as np
import pandana as pdna
import geopandas.io.osm as osm
%matplotlib inline
In [ ]:
gdf = osm.query_osm('node',
bbox=[-122.8662,37.1373,-121.4798,38.2158],
tags='amenity=restaurant')
In [ ]:
gdf = gdf[gdf.type == 'Point'].to_crs(epsg=3740)
print gdf.geometry.head(3)
print len(gdf)
In [ ]:
x, y = zip(*[(p.x, p.y) for (i, p)
in gdf.geometry.iteritems()])
x = pd.Series(x)
y = pd.Series(y)
In [ ]:
store = pd.HDFStore('data/osm_bayarea.h5', "r")
nodes = store.nodes
edges = store.edges
print nodes.head(3)
print edges.head(3)
In [ ]:
net=pdna.Network(nodes.x,
nodes.y,
edges["from"],
edges.to,
edges[["weight"]])
net.precompute(3000)
In [ ]:
net.init_pois(num_categories=1, max_dist=2000, max_pois=10)
In [ ]:
net.set_pois("restaurants", x, y)
In [ ]:
a = net.nearest_pois(2000, "restaurants", num_pois=10)
print a.head(1)
In [ ]:
from shapely.geometry import Point
from fiona.crs import from_epsg
import geopandas as gpd
bbox=[-122.539365,37.693047,-122.347698,37.816069]
bbox = gpd.GeoSeries([Point(bbox[0], bbox[1]),
Point(bbox[2], bbox[3])],
crs=from_epsg(4326))
bbox = bbox.to_crs(epsg=3740)
bbox = [bbox[0].x, bbox[0].y, bbox[1].x, bbox[1].y]
In [ ]:
net.plot(a[1], bbox=bbox, scheme="diverging",
color="BrBG")
In [ ]:
net.plot(a[5], bbox=bbox, scheme="diverging",
color="BrBG")
In [ ]:
net.plot(a[10], bbox=bbox, scheme="diverging",
color="BrBG")
In [ ]:
node_ids = net.get_node_ids(x, y)
In [ ]:
net.set(node_ids)
In [ ]:
%time s = net.aggregate(500, type="sum", decay="linear")
%time t = net.aggregate(1000, type="sum", decay="linear")
%time u = net.aggregate(2000, type="sum", decay="linear")
%time v = net.aggregate(3000, type="sum", decay="linear")
%time w = net.aggregate(3000, type="count", decay="flat")
In [ ]:
net.plot(s, bbox=bbox, scheme="diverging",
color="BrBG", log_scale=True)
In [ ]:
net.plot(t, bbox=bbox, scheme="diverging",
color="BrBG", log_scale=True)
In [ ]:
net.plot(u, bbox=bbox, scheme="diverging",
color="BrBG", log_scale=True)
In [ ]:
net.plot(v, bbox=bbox, scheme="diverging",
color="BrBG", log_scale=True)
In [ ]:
net.plot(v, scheme="diverging",
color="BrBG", log_scale=True)
In [ ]: