|
1 | 1 | from copy import copy |
2 | 2 | from json import dumps, loads |
3 | 3 | from typing import Optional |
4 | | -import math |
5 | 4 |
|
6 | 5 | from fastapi import APIRouter, Request, Response |
| 6 | +from georgio import line_of_bearing # pylint: disable=no-name-in-module |
7 | 7 |
|
8 | 8 | import mercantile |
9 | 9 | import pynumeral |
|
21 | 21 |
|
22 | 22 | router = APIRouter() |
23 | 23 |
|
24 | | -def lob(point, brng, distance): |
25 | | - |
26 | | - R = 6371009 # Radius of the Earth this is the same as georgio |
27 | | - brng = math.radians(brng) # Bearing is degrees converted to radians. |
28 | | - d = distance # Distance in meters |
29 | | - |
30 | | - |
31 | | - lat1 = math.radians(point['lat']) # Current lat point converted to radians |
32 | | - lon1 = math.radians(point['lon']) # Current lon point converted to radians |
33 | | - |
34 | | - lat2 = math.asin(math.sin(lat1)*math.cos(d/R) + |
35 | | - math.cos(lat1)*math.sin(d/R)*math.cos(brng)) |
36 | | - |
37 | | - lon2 = lon1 + math.atan2(math.sin(brng)*math.sin(d/R)*math.cos(lat1), |
38 | | - math.cos(d/R)-math.sin(lat1)*math.sin(lat2)) |
39 | | - |
40 | | - lat2 = math.degrees(lat2) |
41 | | - lon2 = math.degrees(lon2) |
42 | | - return {"lat": lat2, "lon": lon2} |
43 | | - |
44 | 24 | def expand_bbox_by_meters(bbox, meters): |
45 | | - # top left line of bearing nw and bottom right lob se |
46 | | - return {"top_left": lob(bbox['top_left'], 315, meters), "bottom_right": lob(bbox['bottom_right'], 135, meters)} |
47 | | - |
| 25 | + # top left line of bearing NW and bottom right line of bearing SE |
| 26 | + top_left_lon, top_left_lat = line_of_bearing(bbox['top_left']['lon'], bbox['top_left']['lat'], 315, meters) |
| 27 | + bottom_right_lon, bottom_right_lat = line_of_bearing(bbox['bottom_right']['lon'], bbox['bottom_right']['lat'], 135, meters) |
| 28 | + return { |
| 29 | + "top_left": {'lon': top_left_lon, 'lat': top_left_lat}, |
| 30 | + "bottom_right": {'lon': bottom_right_lon, 'lat': bottom_right_lat}, |
| 31 | + } |
48 | 32 |
|
49 | 33 | def legend_response(data: str, error: Optional[Exception]=None, **kwargs) -> Response: |
50 | 34 | headers={ |
|
0 commit comments