37 lines
1.1 KiB
Python
37 lines
1.1 KiB
Python
from __future__ import annotations
|
|
|
|
from fastapi import APIRouter, Depends, Query
|
|
|
|
from app.models.schemas import ElevationProfilePoint, ElevationProfileResponse
|
|
from app.services.link_calculator import LinkCalculator
|
|
|
|
router = APIRouter(prefix="/v1", tags=["elevation"])
|
|
|
|
|
|
def get_link_calculator() -> LinkCalculator:
|
|
from app.main import link_calculator
|
|
|
|
return link_calculator
|
|
|
|
|
|
@router.get("/elevation-profile", response_model=ElevationProfileResponse)
|
|
async def elevation_profile(
|
|
from_lat: float = Query(..., ge=-90, le=90),
|
|
from_lng: float = Query(..., ge=-180, le=180),
|
|
to_lat: float = Query(..., ge=-90, le=90),
|
|
to_lng: float = Query(..., ge=-180, le=180),
|
|
step_m: float = Query(default=30.0, gt=0),
|
|
calculator: LinkCalculator = Depends(get_link_calculator),
|
|
) -> ElevationProfileResponse:
|
|
distance_m, profile = await calculator.elevation_profile(
|
|
from_lat,
|
|
from_lng,
|
|
to_lat,
|
|
to_lng,
|
|
step_m,
|
|
)
|
|
return ElevationProfileResponse(
|
|
distance_m=distance_m,
|
|
path_profile=[ElevationProfilePoint(**point) for point in profile],
|
|
)
|