-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
52 lines (36 loc) · 1.59 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# -*- coding: utf-8 -*-
from flask import Flask
#Application that is running the website
app = Flask(__name__)
@app.route("/")
def index():
#Downloading the datasets
import geopandas as gpd
db_bike_path="data/geo_export_0ff3043a-1833-476b-afe0-779dfa091ebd.shp"
db_bike=gpd.read_file(db_bike_path)
db_roads_path="data/tl_2017_06075_roads.shp"
db_roads=gpd.read_file(db_roads_path)
#Plotting the bike lanes and the streets
from bokeh.plotting import figure
from bokeh.models import GeoJSONDataSource
from bokeh.embed import components
from bokeh.resources import INLINE
from flask import render_template
SF = figure(aspect_scale=1, match_aspect=True)
db_roads_json=GeoJSONDataSource(geojson = db_roads.to_json())
SF.multi_line('xs', 'ys', source=db_roads_json,
color="gray", line_width=0.5,legend="All streets")
db_bike_json=GeoJSONDataSource(geojson = db_bike.to_json())
SF.multi_line('xs', 'ys', source=db_bike_json,
color="red", line_width=1.5,legend="Bike Lanes")
SF.legend.click_policy="hide"
#Convert the plot into HTML and JS that can be read by base.html
script_plot,div_plot=components(SF ,INLINE)
return render_template('plot.html',
script=script_plot,
div=div_plot,
js_resources=INLINE.render_js(),
css_resources=INLINE.render_css())
#Make the website work when we run this python file
if __name__ == "__main__":
app.run(host='0.0.0.0', port=8000, debug=True)