UjjwalKGupta commited on
Commit
a2f255f
·
verified ·
1 Parent(s): 4570239

Add Centroid Coordinates

Browse files
Files changed (1) hide show
  1. app.py +6 -7
app.py CHANGED
@@ -410,13 +410,17 @@ def calculate_geometry_metrics(file_url: str):
410
  # Calculate area (in hectares) and perimeter (in meters)
411
  area_hectares = projected_gdf.area.item() / 10000
412
  perimeter_meters = projected_gdf.length.item()
413
-
414
  # Return the results in a JSON response
415
  return {
416
  "area_hectares": round(area_hectares, 4),
417
  "perimeter_meters": round(perimeter_meters, 4),
 
 
 
 
418
  }
419
-
420
  except ValueError as e:
421
  # Handle specific errors like bad URLs, no polygons, etc. with a 400 Bad Request
422
  raise HTTPException(status_code=400, detail=str(e))
@@ -503,8 +507,6 @@ def calculate_indices(
503
  traceback.print_exc()
504
  return f"An error occurred during calculation: {e}", None, None, None
505
 
506
- # NEW/MODIFIED FUNCTIONS START HERE
507
-
508
  def get_histogram(index_name, image, geometry, bins):
509
  """Calculates the histogram for an image within a given geometry using GEE."""
510
  try:
@@ -867,13 +869,10 @@ for idx in ["NDVI", "EVI", "EVI2", "RandomForest", "CI", "GujVDI"]:
867
 
868
  app.get(endpoint_path)(index_hist_endpoint)
869
 
870
-
871
-
872
  # Mount the Gradio app onto the FastAPI app
873
  app = gr.mount_gradio_app(app, demo, path="/")
874
 
875
 
876
  if __name__ == "__main__":
877
  import uvicorn
878
- # This allows running the app with `python App.py`
879
  uvicorn.run(app, host="0.0.0.0", port=7860)
 
410
  # Calculate area (in hectares) and perimeter (in meters)
411
  area_hectares = projected_gdf.area.item() / 10000
412
  perimeter_meters = projected_gdf.length.item()
413
+
414
  # Return the results in a JSON response
415
  return {
416
  "area_hectares": round(area_hectares, 4),
417
  "perimeter_meters": round(perimeter_meters, 4),
418
+ "centroid": {
419
+ "latitude": round(centroid_point.y, 6),
420
+ "longitude": round(centroid_point.x, 6)
421
+ }
422
  }
423
+
424
  except ValueError as e:
425
  # Handle specific errors like bad URLs, no polygons, etc. with a 400 Bad Request
426
  raise HTTPException(status_code=400, detail=str(e))
 
507
  traceback.print_exc()
508
  return f"An error occurred during calculation: {e}", None, None, None
509
 
 
 
510
  def get_histogram(index_name, image, geometry, bins):
511
  """Calculates the histogram for an image within a given geometry using GEE."""
512
  try:
 
869
 
870
  app.get(endpoint_path)(index_hist_endpoint)
871
 
 
 
872
  # Mount the Gradio app onto the FastAPI app
873
  app = gr.mount_gradio_app(app, demo, path="/")
874
 
875
 
876
  if __name__ == "__main__":
877
  import uvicorn
 
878
  uvicorn.run(app, host="0.0.0.0", port=7860)