Skip to content

Instantly share code, notes, and snippets.

@fscottfoti
Created October 20, 2015 21:54
Show Gist options
  • Save fscottfoti/e2790359bd194f299262 to your computer and use it in GitHub Desktop.
Save fscottfoti/e2790359bd194f299262 to your computer and use it in GitHub Desktop.
pandana example POI query
def make_network(name, weight_col, max_distance):
st = pd.HDFStore(os.path.join(misc.data_dir(), name), "r")
nodes, edges = st.nodes, st.edges
net = pdna.Network(nodes["x"], nodes["y"], edges["from"], edges["to"],
edges[[weight_col]])
net.precompute(max_distance)
return net
@orca.step('local_pois')
def local_pois(settings):
# because of the aforementioned limit of one netowrk at a time for the
# POIS, as well as the large amount of memory used, this is now a
# preprocessing step
n = make_network(
settings['build_networks']['walk']['name'],
"weight", 3000)
n.init_pois(
num_categories=1,
max_dist=3000,
max_pois=1)
cols = {}
locations = pd.read_csv(os.path.join(misc.data_dir(), 'bart_stations.csv'))
n.set_pois("tmp", locations.lng, locations.lat)
cols["bartdist"] = n.nearest_pois(3000, "tmp", num_pois=1)[1]
locname = 'pacheights'
locs = orca.get_table('locations').local.query("name == '%s'" % locname)
n.set_pois("tmp", locs.lng, locs.lat)
cols["pacheights"] = n.nearest_pois(3000, "tmp", num_pois=1)[1]
df = pd.DataFrame(cols)
df.index.name = "node_id"
df.to_csv('local_poi_distances.csv')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment