UjjwalKGupta commited on
Commit
d4a0148
·
verified ·
1 Parent(s): 4c050c0

Add LayerControl to KMLMap

Browse files
Files changed (1) hide show
  1. app.py +2 -11
app.py CHANGED
@@ -365,6 +365,7 @@ def process_and_display(file_obj, url_str, buffer_m, progress=gr.Progress()):
365
  bounds = geometry_gdf.to_crs(epsg=4326).total_bounds
366
  map_bounds = [[bounds[1], bounds[0]], [bounds[3], bounds[2]]]
367
  m.fit_bounds(map_bounds, padding=(10, 10))
 
368
 
369
  ee_geometry = ee.Geometry(json.loads(geometry_gdf.to_crs(4326).to_json())['features'][0]['geometry'])
370
  dem_html, slope_html = get_dem_slope_maps(ee_geometry, map_bounds, wayback_url=wayback_url, wayback_title=wayback_title)
@@ -387,24 +388,16 @@ def calculate_geometry_metrics(file_url: str):
387
  perimeter of the first valid polygon, and returns the results.
388
  """
389
  try:
390
- # Decode URL-encoded characters
391
  decoded_url = unquote(file_url)
392
-
393
- # Fetch and parse the spatial data
394
  input_gdf = get_gdf_from_url(decoded_url)
395
  if input_gdf is None or input_gdf.empty:
396
  raise ValueError("Could not read geometry from the provided URL.")
397
-
398
- # Clean up geometries (e.g., fix invalid polygons)
399
  input_gdf = preprocess_gdf(input_gdf)
400
-
401
- # Find the first valid polygon in the GeoDataFrame
402
  geometry_gdf = next((input_gdf.iloc[[i]] for i in range(len(input_gdf)) if is_valid_polygon(input_gdf.iloc[[i]])), None)
403
 
404
  if geometry_gdf is None:
405
  raise ValueError("No valid polygon found in the provided file.")
406
-
407
- # Project to a suitable CRS for accurate measurements
408
  projected_gdf = to_best_crs(geometry_gdf)
409
 
410
  # Calculate area (in hectares) and perimeter (in meters)
@@ -415,7 +408,6 @@ def calculate_geometry_metrics(file_url: str):
415
  centroid_gdf = projected_gdf.to_crs(epsg=4326)
416
  centroid_point = centroid_gdf.centroid.item()
417
 
418
- # Return the results in a JSON response
419
  return {
420
  "area_hectares": round(area_hectares, 4),
421
  "perimeter_meters": round(perimeter_meters, 4),
@@ -553,7 +545,6 @@ def generate_comparison_maps(geometry_json, selected_index, selected_years, evi_
553
  start_date = f"{year}-{start_month:02d}-{start_day:02d}"
554
  end_date = f"{year}-{end_month:02d}-{end_day:02d}"
555
 
556
- # --- Wayback Basemap Logic (unchanged) ---
557
  wayback_url = None
558
  wayback_title = "Default Satellite"
559
  if not WAYBACK_DF.empty:
 
365
  bounds = geometry_gdf.to_crs(epsg=4326).total_bounds
366
  map_bounds = [[bounds[1], bounds[0]], [bounds[3], bounds[2]]]
367
  m.fit_bounds(map_bounds, padding=(10, 10))
368
+ m.addLayerControl()
369
 
370
  ee_geometry = ee.Geometry(json.loads(geometry_gdf.to_crs(4326).to_json())['features'][0]['geometry'])
371
  dem_html, slope_html = get_dem_slope_maps(ee_geometry, map_bounds, wayback_url=wayback_url, wayback_title=wayback_title)
 
388
  perimeter of the first valid polygon, and returns the results.
389
  """
390
  try:
391
+
392
  decoded_url = unquote(file_url)
 
 
393
  input_gdf = get_gdf_from_url(decoded_url)
394
  if input_gdf is None or input_gdf.empty:
395
  raise ValueError("Could not read geometry from the provided URL.")
 
 
396
  input_gdf = preprocess_gdf(input_gdf)
 
 
397
  geometry_gdf = next((input_gdf.iloc[[i]] for i in range(len(input_gdf)) if is_valid_polygon(input_gdf.iloc[[i]])), None)
398
 
399
  if geometry_gdf is None:
400
  raise ValueError("No valid polygon found in the provided file.")
 
 
401
  projected_gdf = to_best_crs(geometry_gdf)
402
 
403
  # Calculate area (in hectares) and perimeter (in meters)
 
408
  centroid_gdf = projected_gdf.to_crs(epsg=4326)
409
  centroid_point = centroid_gdf.centroid.item()
410
 
 
411
  return {
412
  "area_hectares": round(area_hectares, 4),
413
  "perimeter_meters": round(perimeter_meters, 4),
 
545
  start_date = f"{year}-{start_month:02d}-{start_day:02d}"
546
  end_date = f"{year}-{end_month:02d}-{end_day:02d}"
547
 
 
548
  wayback_url = None
549
  wayback_title = "Default Satellite"
550
  if not WAYBACK_DF.empty: