Add Comparison Map
Browse files
app.py
CHANGED
|
@@ -467,6 +467,29 @@ def generate_comparison_maps(geometry_json, selected_index, selected_years, evi_
|
|
| 467 |
progress((i + 1) / 2, desc=f"Generating map for {year}")
|
| 468 |
start_date = f"{year}-{start_month:02d}-{start_day:02d}"
|
| 469 |
end_date = f"{year}-{end_month:02d}-{end_day:02d}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 470 |
|
| 471 |
collection = (
|
| 472 |
ee.ImageCollection("COPERNICUS/S2_SR_HARMONIZED")
|
|
@@ -486,8 +509,13 @@ def generate_comparison_maps(geometry_json, selected_index, selected_years, evi_
|
|
| 486 |
mosaic = collection.qualityMosaic(selected_index)
|
| 487 |
clipped_image = mosaic.select(selected_index).clip(ee_geometry)
|
| 488 |
|
|
|
|
| 489 |
m = gee_folium.Map(zoom_start=14)
|
| 490 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 491 |
m.addLayer(clipped_image, vis_params, f"{selected_index} {year}")
|
| 492 |
m.add_colorbar(vis_params=vis_params, label=f"{selected_index} Value")
|
| 493 |
folium.GeoJson(geometry_gdf, name="Geometry", style_function=lambda x: {"color": "yellow", "fillOpacity": 0, "weight": 2.5}).add_to(m)
|
|
|
|
| 467 |
progress((i + 1) / 2, desc=f"Generating map for {year}")
|
| 468 |
start_date = f"{year}-{start_month:02d}-{start_day:02d}"
|
| 469 |
end_date = f"{year}-{end_month:02d}-{end_day:02d}"
|
| 470 |
+
|
| 471 |
+
wayback_url = None
|
| 472 |
+
wayback_title = "Default Satellite"
|
| 473 |
+
if not WAYBACK_DF.empty:
|
| 474 |
+
try:
|
| 475 |
+
target_date = datetime(int(year), start_month, 15)
|
| 476 |
+
# Find the index of the closest date in the wayback dataframe
|
| 477 |
+
nearest_idx = WAYBACK_DF.index.get_indexer([target_date], method='nearest')[0]
|
| 478 |
+
wayback_item = WAYBACK_DF.iloc[nearest_idx]
|
| 479 |
+
|
| 480 |
+
wayback_title = f"Esri Wayback ({wayback_item.name.strftime('%Y-%m-%d')})"
|
| 481 |
+
wayback_url = (
|
| 482 |
+
wayback_item["ResourceURL_Template"]
|
| 483 |
+
.replace("{TileMatrixSet}", "GoogleMapsCompatible")
|
| 484 |
+
.replace("{TileMatrix}", "{z}")
|
| 485 |
+
.replace("{TileRow}", "{y}")
|
| 486 |
+
.replace("{TileCol}", "{x}")
|
| 487 |
+
)
|
| 488 |
+
except Exception as e:
|
| 489 |
+
print(f"Could not find a suitable Wayback basemap for {year}: {e}")
|
| 490 |
+
# Fallback to default values if any error occurs
|
| 491 |
+
wayback_url = None
|
| 492 |
+
wayback_title = "Default Satellite"
|
| 493 |
|
| 494 |
collection = (
|
| 495 |
ee.ImageCollection("COPERNICUS/S2_SR_HARMONIZED")
|
|
|
|
| 509 |
mosaic = collection.qualityMosaic(selected_index)
|
| 510 |
clipped_image = mosaic.select(selected_index).clip(ee_geometry)
|
| 511 |
|
| 512 |
+
# Create map and add the year-specific basemap
|
| 513 |
m = gee_folium.Map(zoom_start=14)
|
| 514 |
+
if wayback_url:
|
| 515 |
+
m.add_tile_layer(wayback_url, name=wayback_title, attribution="Esri")
|
| 516 |
+
else:
|
| 517 |
+
m.add_basemap("SATELLITE")
|
| 518 |
+
|
| 519 |
m.addLayer(clipped_image, vis_params, f"{selected_index} {year}")
|
| 520 |
m.add_colorbar(vis_params=vis_params, label=f"{selected_index} Value")
|
| 521 |
folium.GeoJson(geometry_gdf, name="Geometry", style_function=lambda x: {"color": "yellow", "fillOpacity": 0, "weight": 2.5}).add_to(m)
|