Ekaropolus 0eb2b393f2
All checks were successful
continuous-integration/drone/push Build is passing
SAMI Functionality add
2025-09-16 16:18:45 -06:00

44 lines
1.5 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

from __future__ import annotations
from typing import Dict, Any, Tuple, List
import os
from pyproj import Geod
LatLon = Tuple[float, float]
class CrowFlyRoutingProvider:
"""
Isócrona aproximada como círculo geodésico:
radio = velocidad_km_h * (minutos / 60.0)
Útil para demos sin depender de motores externos.
"""
def __init__(self) -> None:
self._geod = Geod(ellps="WGS84")
# Puedes ajustar la velocidad por entorno (urbana 2535 km/h es razonable)
self._speed_kmh = float(os.getenv("ROUTING_CROWFLY_SPEED_KMH", "30"))
def health(self) -> Dict[str, Any]:
return {"provider": "crowfly", "ok": True, "speed_kmh": self._speed_kmh}
def isochrone(self, center: LatLon, minutes: int) -> Dict[str, Any]:
lat, lon = float(center[0]), float(center[1])
# distancia en metros
km = self._speed_kmh * (float(minutes) / 60.0)
dist_m = km * 1000.0
# polígono aproximado (64 segmentos)
coords: List[Tuple[float, float]] = []
for b in range(0, 360, 360 // 64):
lon2, lat2, _ = self._geod.fwd(lon, lat, b, dist_m)
coords.append((lon2, lat2))
coords.append(coords[0]) # cerrar
# GeoJSON-like
return {
"type": "Feature",
"properties": {"minutes": minutes, "speed_kmh": self._speed_kmh},
"geometry": {
"type": "Polygon",
"coordinates": [coords], # lon,lat
},
}