UjjwalKGupta commited on
Commit
141fbc6
·
verified ·
1 Parent(s): 83257c7

update geometry as per csv

Browse files
Files changed (1) hide show
  1. app.py +5 -17
app.py CHANGED
@@ -444,31 +444,19 @@ def calculate_geometry_metrics(file_url: str):
444
  raise ValueError("No valid polygon found in the provided file.")
445
 
446
  projected_gdf = to_best_crs(geometry_gdf)
447
-
448
- # Calculate area (in hectares) and perimeter (in meters)
449
  area_hectares = projected_gdf.area.item() / 10000
450
  perimeter_meters = projected_gdf.length.item()
451
 
452
- # reproject to WGS84 (EPSG:4326) for centroid
453
  centroid_gdf = projected_gdf.to_crs(epsg=4326)
454
  centroid_point = centroid_gdf.centroid.item()
455
 
456
- # --- CSV Formatting ---
457
- # 1. Define the header row
458
- header = "area_hectares,perimeter_meters,latitude,longitude"
459
-
460
- # 2. Define the data row, rounding the values
461
  data_row = (
462
- f"{round(area_hectares, 4)},"
463
- f"{round(perimeter_meters, 4)},"
464
- f"{round(centroid_point.y, 4)},"
465
- f"{round(centroid_point.x, 4)}"
466
  )
467
-
468
- # 3. Combine header and data with a newline character
469
- csv_output = f"{header}\n{data_row}"
470
-
471
- # 4. Return the CSV string with the correct media type
472
  return Response(content=csv_output, media_type="text/csv")
473
 
474
  except ValueError as e:
 
444
  raise ValueError("No valid polygon found in the provided file.")
445
 
446
  projected_gdf = to_best_crs(geometry_gdf)
 
 
447
  area_hectares = projected_gdf.area.item() / 10000
448
  perimeter_meters = projected_gdf.length.item()
449
 
 
450
  centroid_gdf = projected_gdf.to_crs(epsg=4326)
451
  centroid_point = centroid_gdf.centroid.item()
452
 
 
 
 
 
 
453
  data_row = (
454
+ f"{area_hectares, round(area_hectares, 4)},"
455
+ f"{perimeter_meters,round(perimeter_meters, 4)},"
456
+ f"{latitude, round(centroid_point.y, 4)},"
457
+ f"{longitude, round(centroid_point.x, 4)}"
458
  )
459
+ csv_output = f"{data_row}"
 
 
 
 
460
  return Response(content=csv_output, media_type="text/csv")
461
 
462
  except ValueError as e: