YashMK89 commited on
Commit
651adc3
·
verified ·
1 Parent(s): 13c20d0

update app.py

Browse files
Files changed (1) hide show
  1. app.py +58 -1
app.py CHANGED
@@ -6,6 +6,7 @@ import pandas as pd
6
  import geopandas as gpd
7
  from datetime import datetime
8
  from shapely.geometry import Point
 
9
 
10
  # Set up the page layout
11
  st.set_page_config(layout="wide")
@@ -114,7 +115,63 @@ if parameters_changed():
114
  'end_date_str': end_date_str
115
  }
116
 
117
- # Function to perform index calculations
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
118
  def calculate_ndvi(image, geometry):
119
  ndvi = image.normalizedDifference(['B8', 'B4']).rename('NDVI')
120
  return ndvi.reduceRegion(
 
6
  import geopandas as gpd
7
  from datetime import datetime
8
  from shapely.geometry import Point
9
+ import leafmap.foliumap as leafmap
10
 
11
  # Set up the page layout
12
  st.set_page_config(layout="wide")
 
115
  'end_date_str': end_date_str
116
  }
117
 
118
+ # Process file and display map
119
+ locations_df = None # Initialize locations_df to None
120
+ polygons_df = None # Initialize polygons_df to None
121
+
122
+ if file_upload:
123
+ file_extension = os.path.splitext(file_upload.name)[1].lower()
124
+
125
+ # Read file based on shape type
126
+ if shape_type == 'Point':
127
+ if file_extension == '.csv':
128
+ locations_df = read_csv(file_upload)
129
+ elif file_extension == '.geojson':
130
+ locations_df = read_geojson(file_upload)
131
+ elif file_extension == '.kml':
132
+ locations_df = read_kml(file_upload)
133
+ else:
134
+ st.error("Unsupported file type. Please upload a CSV, GeoJSON, or KML file for points.")
135
+ elif shape_type == 'Polygon':
136
+ if file_extension == '.geojson':
137
+ polygons_df = read_geojson(file_upload)
138
+ elif file_extension == '.kml':
139
+ polygons_df = read_kml(file_upload)
140
+ else:
141
+ st.error("Unsupported file type. Please upload a GeoJSON or KML file for polygons.")
142
+
143
+ # If there are points, display them on the map
144
+ if locations_df is not None:
145
+ st.write("Preview of the uploaded points data:")
146
+ st.dataframe(locations_df.head())
147
+
148
+ # Create a LeafMap object to display the points
149
+ m = leafmap.Map(center=[locations_df['latitude'].mean(), locations_df['longitude'].mean()], zoom=10)
150
+
151
+ for _, row in locations_df.iterrows():
152
+ m.add_marker(location=[row['latitude'], row['longitude']], popup=row.get('name', 'No Name'))
153
+
154
+ # Display map
155
+ st.write("Map of Uploaded Points:")
156
+ m.to_streamlit()
157
+
158
+ # If there are polygons, display them on the map
159
+ if polygons_df is not None:
160
+ st.write("Preview of the uploaded polygons data:")
161
+ st.dataframe(polygons_df.head())
162
+
163
+ # Create a LeafMap object to display the polygons
164
+ m = leafmap.Map(center=[polygons_df.geometry.centroid.y.mean(), polygons_df.geometry.centroid.x.mean()], zoom=10)
165
+
166
+ # Plot polygons on the map
167
+ for _, row in polygons_df.iterrows():
168
+ m.add_geojson(geojson=row['geometry'].__geo_interface__)
169
+
170
+ # Display map
171
+ st.write("Map of Uploaded Polygons:")
172
+ m.to_streamlit()
173
+
174
+ # Function to perform index calculations (as before)
175
  def calculate_ndvi(image, geometry):
176
  ndvi = image.normalizedDifference(['B8', 'B4']).rename('NDVI')
177
  return ndvi.reduceRegion(