better structure
Some checks failed
Build and deploy the backend to staging / Build and push image (pull_request) Successful in 1m45s
Run linting on the backend code / Build (pull_request) Successful in 27s
Run testing on the backend code / Build (pull_request) Failing after 45s
Build and deploy the backend to staging / Deploy to staging (pull_request) Successful in 25s
Some checks failed
Build and deploy the backend to staging / Build and push image (pull_request) Successful in 1m45s
Run linting on the backend code / Build (pull_request) Successful in 27s
Run testing on the backend code / Build (pull_request) Failing after 45s
Build and deploy the backend to staging / Deploy to staging (pull_request) Successful in 25s
This commit is contained in:
27
backend/src/utils/bbox.py
Normal file
27
backend/src/utils/bbox.py
Normal file
@@ -0,0 +1,27 @@
|
||||
"""Various helper functions"""
|
||||
import math as m
|
||||
|
||||
def create_bbox(coords: tuple[float, float], radius: int):
|
||||
"""
|
||||
Create a bounding box around the given coordinates.
|
||||
|
||||
Args:
|
||||
coords (tuple[float, float]): The latitude and longitude of the center of the bounding box.
|
||||
radius (int): The half-side length of the bounding box in meters.
|
||||
|
||||
Returns:
|
||||
tuple[float, float, float, float]: The minimum latitude, minimum longitude, maximum latitude, and maximum longitude
|
||||
defining the bounding box.
|
||||
"""
|
||||
# Earth's radius in meters
|
||||
R = 6378137
|
||||
lat, lon = coords
|
||||
d_lat = radius / R
|
||||
d_lon = radius / (R * m.cos(m.pi * lat / 180))
|
||||
|
||||
lat_min = lat - d_lat * 180 / m.pi
|
||||
lat_max = lat + d_lat * 180 / m.pi
|
||||
lon_min = lon - d_lon * 180 / m.pi
|
||||
lon_max = lon + d_lon * 180 / m.pi
|
||||
|
||||
return (lat_min, lon_min, lat_max, lon_max)
|
||||
Reference in New Issue
Block a user