aassiiyAA123 commited on
Commit
9f566ad
·
verified ·
1 Parent(s): 8db0c76

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -9
app.py CHANGED
@@ -2327,7 +2327,17 @@ def Morphometric_Analysis_for_Watershedstreams_page():
2327
  Morphometric_Analysis_for_Watershedstreams()
2328
 
2329
  #------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
2330
-
 
 
 
 
 
 
 
 
 
 
2331
 
2332
  def Morphometric_Analysis_for_Watershedstreams():
2333
  translator = google_translator()
@@ -2337,11 +2347,11 @@ def Morphometric_Analysis_for_Watershedstreams():
2337
  draw = Draw(export=True, filename='drawn_shapes') # Initialize the Draw plugin
2338
  draw.add_to(Map)
2339
 
2340
-
2341
  # Language selection
2342
  language = st.sidebar.selectbox("Select Language", ["English", "Spanish", "French", "German", "Chinese"])
2343
 
2344
  uploaded_file = st.file_uploader("Upload a KML file or other supported format")
 
2345
  @st.cache_data
2346
  def uploaded_file_to_gdf(data):
2347
  _, file_extension = os.path.splitext(data.name)
@@ -2367,7 +2377,6 @@ def Morphometric_Analysis_for_Watershedstreams():
2367
 
2368
  st.sidebar.header(translate_text("Map Controls"))
2369
 
2370
- # Caching to improve performance
2371
  @st.cache_data
2372
  def get_dem_layers():
2373
  return {
@@ -2396,7 +2405,9 @@ def Morphometric_Analysis_for_Watershedstreams():
2396
  'Local Watershed Dataset': ee.FeatureCollection("users/mynet34/1HAVZA/4_CATCHMENT_1"),
2397
  }
2398
 
2399
-
 
 
2400
 
2401
  # Function to add DEM layers
2402
  def add_dem_layer(choice):
@@ -2439,17 +2450,22 @@ def Morphometric_Analysis_for_Watershedstreams():
2439
  st.sidebar.warning(translate_text("Please draw a shape on the map first."))
2440
  return
2441
 
2442
- # Extract elevation data along the shape
2443
  dem_image = ee.Image('JAXA/ALOS/AW3D30/V2_2').select(['AVE_DSM'], ['b1'])
 
 
 
 
 
2444
  shape_coords = shape.geometry().coordinates().getInfo()
2445
-
2446
  # Convert shape coordinates into a feature collection
2447
  shape_fc = ee.FeatureCollection([
2448
  ee.Feature(ee.Geometry.Point(coord)) for coord in shape_coords
2449
  ])
2450
 
2451
  # Sample elevation values along the shape
2452
- elevation_values = dem_image.sampleRegions(
2453
  collection=shape_fc,
2454
  scale=30,
2455
  geometries=True
@@ -2478,7 +2494,6 @@ def Morphometric_Analysis_for_Watershedstreams():
2478
  plt.ylabel(translate_text("Elevation (m)"))
2479
  st.pyplot(plt)
2480
 
2481
-
2482
  # Button to calculate the elevation profile
2483
  if st.sidebar.button(translate_text("Calculate Elevation Profile")):
2484
  calculate_elevation_profile()
@@ -2558,7 +2573,6 @@ def Morphometric_Analysis_for_Watershedstreams():
2558
  # Export/download options
2559
  st.sidebar.download_button(label=translate_text("Export Analysis as CSV"), data="Generated Data", file_name="analysis.csv", mime="text/csv")
2560
  st.sidebar.download_button(label=translate_text("Download Map Screenshot"), data="Map Screenshot", file_name="map.png", mime="image/png")
2561
-
2562
 
2563
  #---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
2564
  # Create a dictionary of pages
 
2327
  Morphometric_Analysis_for_Watershedstreams()
2328
 
2329
  #------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
2330
+ import os
2331
+ import uuid
2332
+ import tempfile
2333
+ import streamlit as st
2334
+ import geopandas as gpd
2335
+ import geemap
2336
+ import plotly.graph_objects as go
2337
+ import matplotlib.pyplot as plt
2338
+ import ee
2339
+ from google_trans_new import google_translator
2340
+ from streamlit_draw import Draw
2341
 
2342
  def Morphometric_Analysis_for_Watershedstreams():
2343
  translator = google_translator()
 
2347
  draw = Draw(export=True, filename='drawn_shapes') # Initialize the Draw plugin
2348
  draw.add_to(Map)
2349
 
 
2350
  # Language selection
2351
  language = st.sidebar.selectbox("Select Language", ["English", "Spanish", "French", "German", "Chinese"])
2352
 
2353
  uploaded_file = st.file_uploader("Upload a KML file or other supported format")
2354
+
2355
  @st.cache_data
2356
  def uploaded_file_to_gdf(data):
2357
  _, file_extension = os.path.splitext(data.name)
 
2377
 
2378
  st.sidebar.header(translate_text("Map Controls"))
2379
 
 
2380
  @st.cache_data
2381
  def get_dem_layers():
2382
  return {
 
2405
  'Local Watershed Dataset': ee.FeatureCollection("users/mynet34/1HAVZA/4_CATCHMENT_1"),
2406
  }
2407
 
2408
+ # Function to clip image to shape
2409
+ def clip_image_to_shape(image, shape):
2410
+ return image.clip(shape.geometry())
2411
 
2412
  # Function to add DEM layers
2413
  def add_dem_layer(choice):
 
2450
  st.sidebar.warning(translate_text("Please draw a shape on the map first."))
2451
  return
2452
 
2453
+ # Sample DEM image
2454
  dem_image = ee.Image('JAXA/ALOS/AW3D30/V2_2').select(['AVE_DSM'], ['b1'])
2455
+
2456
+ # Clip the DEM image to the drawn shape
2457
+ clipped_dem = clip_image_to_shape(dem_image, shape)
2458
+
2459
+ # Extract elevation data along the shape
2460
  shape_coords = shape.geometry().coordinates().getInfo()
2461
+
2462
  # Convert shape coordinates into a feature collection
2463
  shape_fc = ee.FeatureCollection([
2464
  ee.Feature(ee.Geometry.Point(coord)) for coord in shape_coords
2465
  ])
2466
 
2467
  # Sample elevation values along the shape
2468
+ elevation_values = clipped_dem.sampleRegions(
2469
  collection=shape_fc,
2470
  scale=30,
2471
  geometries=True
 
2494
  plt.ylabel(translate_text("Elevation (m)"))
2495
  st.pyplot(plt)
2496
 
 
2497
  # Button to calculate the elevation profile
2498
  if st.sidebar.button(translate_text("Calculate Elevation Profile")):
2499
  calculate_elevation_profile()
 
2573
  # Export/download options
2574
  st.sidebar.download_button(label=translate_text("Export Analysis as CSV"), data="Generated Data", file_name="analysis.csv", mime="text/csv")
2575
  st.sidebar.download_button(label=translate_text("Download Map Screenshot"), data="Map Screenshot", file_name="map.png", mime="image/png")
 
2576
 
2577
  #---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
2578
  # Create a dictionary of pages