-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.py
More file actions
34 lines (28 loc) · 1.03 KB
/
app.py
File metadata and controls
34 lines (28 loc) · 1.03 KB
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
from flask import Flask, render_template, jsonify
import geopandas as gpd
import json
app = Flask(__name__)
gdf = gpd.read_feather('data/final/final_sal.feather').to_crs(epsg=4326)
# Convert gdf to GeoJSON
def gdf_to_geojson(gdf, properties):
gdf['features'] = gdf.apply(lambda row: {
'type': 'Feature',
'geometry': json.loads(row['geometry'].to_json()),
'properties': {prop: row[prop] for prop in properties}
}, axis=1)
return json.dumps({
'type': 'FeatureCollection',
'features': list(gdf['features'])
})
@app.route('/')
def index():
return render_template('index.html', amenity_type=['restaurant', 'cafe', 'school'],
stat_type=['within 2km', 'within 1km', 'within 500m', 'within 200m', 'closest'])
@app.route('/data/<amenity>/<stat>')
def data(amenity, stat):
col_name = f'{amenity} - {stat}'
properties = [col_name]
geojson_data = gdf_to_geojson(gdf, properties)
return jsonify(geojson_data)
if __name__ == '__main__':
app.run(debug=True)