Skip to content

Commit 2ea188c

Browse files
Switched to georgio.line_of_bearing().
1 parent aa17b12 commit 2ea188c

File tree

2 files changed

+11
-27
lines changed

2 files changed

+11
-27
lines changed

elastic_datashader/routers/legend.py

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
from copy import copy
22
from json import dumps, loads
33
from typing import Optional
4-
import math
54

65
from fastapi import APIRouter, Request, Response
6+
from georgio import line_of_bearing # pylint: disable=no-name-in-module
77

88
import mercantile
99
import pynumeral
@@ -21,30 +21,14 @@
2121

2222
router = APIRouter()
2323

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-
4424
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+
}
4832

4933
def legend_response(data: str, error: Optional[Exception]=None, **kwargs) -> Response:
5034
headers={

pyproject.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ python = ">=3.10,<4"
2424
elasticsearch = "7.17.4"
2525
elasticsearch-dsl = "7.4.0"
2626
datashader = "0.14.2"
27-
pandas = "*"
28-
colorcet = "*"
27+
pandas = "^1.5.3"
28+
colorcet = "^3.0.1"
2929
mercantile = "1.2.1"
3030
pypng = "*"
3131
Pillow = "*"
@@ -38,7 +38,7 @@ PyYAML = "*"
3838
humanize = "*"
3939
uvicorn = {extras = ["standard"], version = "^0.18.2", optional = true}
4040
fastapi = "^0.86"
41-
georgio = "2022.335.152"
41+
georgio = "2023.119.77"
4242

4343
[tool.poetry.dev-dependencies]
4444
pytest = "*"

0 commit comments

Comments
 (0)