Spaces:
Configuration error
Configuration error
File size: 1,591 Bytes
41be7ed | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | import requests
from typing import Dict, Any, List, Tuple
# Rough bounding box for Hyderabad, India (approximate)
# swlat, swlng (bottom-left) and nelat, nelng (top-right)
HYD_BBOX = (17.200, 78.200, 17.650, 78.650)
INAT_ENDPOINT = "https://api.inaturalist.org/v1/observations"
def hyderabad_bbox() -> Tuple[float, float, float, float]:
return HYD_BBOX
def find_observations_in_hyd(taxon_name: str, per_page: int = 30) -> List[Dict[str, Any]]:
swlat, swlng, nelat, nelng = HYD_BBOX
params = {
"taxon_name": taxon_name,
"swlat": swlat,
"swlng": swlng,
"nelat": nelat,
"nelng": nelng,
"order": "desc",
"order_by": "created_at",
"per_page": per_page,
}
r = requests.get(INAT_ENDPOINT, params=params, timeout=30)
r.raise_for_status()
data = r.json()
return data.get("results", [])
def observations_to_markers(observations: List[Dict[str, Any]]):
markers = []
for o in observations:
coords = o.get("geojson", {}).get("coordinates")
if not coords or len(coords) != 2:
# fallback
lat = o.get("location", ",").split(",")[0] if o.get("location") else None
lng = o.get("location", ",").split(",")[1] if o.get("location") else None
if lat and lng:
try:
markers.append((float(lat), float(lng), o))
except Exception:
continue
continue
lng, lat = coords # iNat stores as [lng, lat]
markers.append((lat, lng, o))
return markers
|