-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
65 lines (51 loc) · 1.4 KB
/
main.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
53
54
55
56
57
58
59
60
61
62
63
import json
from flask import Flask, Response, make_response, send_file, request
from flask_cors import CORS
from constants import host, port
from core.Point import Point
from utils import get_altitude, interpolate, group
app = Flask(__name__)
CORS(app)
@app.route("/tiles/<z>/<x>/<y>", methods=["GET"])
def tiles(z, x, y):
try:
path = f'data/tiles/{z}/{x}/{y}.png'
return send_file(path)
except:
return Response(status=404)
@app.route("/height/<lat>/<lon>", methods=["GET"])
def height(lat, lon):
try:
point = Point(lat, lon)
return make_response(point.json(), 200)
except:
return Response(status=404)
@app.route("/height/raster/<z>/<x>/<y>", methods=["GET"])
def raster(z, x, y):
try:
path = f'data/rgb/{z}/{x}/{y}.png'
return send_file(path)
except:
return Response(status=404)
@app.route("/height/profile", methods=["POST"])
def profile():
try:
body = group(json.loads(request.data))
interpolated_path = []
for line in body:
interpolated_path.append(interpolate(line[0], line[1]))
result = []
for line in interpolated_path:
for point in line:
alt = int(get_altitude(point[1], point[0]))
result.append([*point, alt])
print(result)
return make_response(json.dumps(result), 200)
except:
return Response(status=404)
if __name__ == '__main__':
app.run(
host=host,
port=port,
debug=True
)