Spaces:
Configuration error
Configuration error
| 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 | |