Spaces:
Running
Running
Update main.py
Browse files
main.py
CHANGED
|
@@ -485,19 +485,23 @@ def map_worldcover_to_terrain_simplified(code: int, lat: float, lon: float, elev
|
|
| 485 |
return "Tundra"
|
| 486 |
|
| 487 |
else:
|
| 488 |
-
# Unknown codes -
|
| 489 |
if elevation is not None:
|
| 490 |
if elevation >= -2: # Onshore water body threshold
|
| 491 |
-
return "Water Body"
|
| 492 |
-
elif elevation < -2: # Marine water
|
| 493 |
-
depth = -elevation
|
| 494 |
if depth <= 200:
|
| 495 |
return "Continental Shelf"
|
| 496 |
else:
|
| 497 |
-
return "Deep Ocean"
|
| 498 |
-
elif
|
| 499 |
return "Tidal Zone"
|
| 500 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 501 |
return "Unknown"
|
| 502 |
|
| 503 |
def detect_coastal_area(lat: float, lon: float, elevation: Optional[float], landcover_analysis: Optional[LandCoverAnalysis]) -> bool:
|
|
@@ -767,6 +771,22 @@ async def classify_terrain_enhanced_async(lat: float, lon: float, radius_meters:
|
|
| 767 |
|
| 768 |
# SIMPLIFIED terrain classification logic
|
| 769 |
final_terrain = terrain
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 770 |
|
| 771 |
# Override terrain classification based on elevation for water bodies
|
| 772 |
if elev is not None and terrain in ["Water Body", "Continental Shelf", "Deep Ocean"]:
|
|
|
|
| 485 |
return "Tundra"
|
| 486 |
|
| 487 |
else:
|
| 488 |
+
# Unknown codes - IMPROVED logic for water classification when WorldCover fails
|
| 489 |
if elevation is not None:
|
| 490 |
if elevation >= -2: # Onshore water body threshold
|
| 491 |
+
return "Water Body"
|
| 492 |
+
elif elevation < -2: # Marine water - THIS IS THE KEY FIX
|
| 493 |
+
depth = -elevation # Convert negative elevation to positive depth
|
| 494 |
if depth <= 200:
|
| 495 |
return "Continental Shelf"
|
| 496 |
else:
|
| 497 |
+
return "Deep Ocean" # This should now work for deep ocean
|
| 498 |
+
elif is_coastal_location(lat, lon, elevation) and elevation <= 10:
|
| 499 |
return "Tidal Zone"
|
| 500 |
|
| 501 |
+
# If no elevation data available, try to infer from location
|
| 502 |
+
if is_coastal_location(lat, lon, elevation):
|
| 503 |
+
return "Tidal Zone"
|
| 504 |
+
|
| 505 |
return "Unknown"
|
| 506 |
|
| 507 |
def detect_coastal_area(lat: float, lon: float, elevation: Optional[float], landcover_analysis: Optional[LandCoverAnalysis]) -> bool:
|
|
|
|
| 771 |
|
| 772 |
# SIMPLIFIED terrain classification logic
|
| 773 |
final_terrain = terrain
|
| 774 |
+
|
| 775 |
+
if terrain == "Unknown" and elev is not None:
|
| 776 |
+
# Use elevation-only classification for ocean areas
|
| 777 |
+
if elev < -2: # Marine water
|
| 778 |
+
depth = -elev
|
| 779 |
+
if depth <= 200:
|
| 780 |
+
terrain = "Continental Shelf"
|
| 781 |
+
else:
|
| 782 |
+
terrain = "Deep Ocean"
|
| 783 |
+
elif elev >= -2 and elev <= 0:
|
| 784 |
+
terrain = "Water Body"
|
| 785 |
+
elif is_coastal_location(lat, lon, elev) and elev <= 10:
|
| 786 |
+
terrain = "Tidal Zone"
|
| 787 |
+
|
| 788 |
+
# Coastal detection
|
| 789 |
+
is_coastal = detect_coastal_area(lat, lon, elev, landcover_analysis)
|
| 790 |
|
| 791 |
# Override terrain classification based on elevation for water bodies
|
| 792 |
if elev is not None and terrain in ["Water Body", "Continental Shelf", "Deep Ocean"]:
|