YashMK89 commited on
Commit
f518995
·
verified ·
1 Parent(s): 919420f

update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -38
app.py CHANGED
@@ -182,51 +182,47 @@ if file_upload:
182
  else:
183
  st.error("Unsupported file type. Please upload a GeoJSON or KML file for polygons.")
184
 
 
185
  if locations_df is not None:
186
- # Display a preview of the points data
187
  st.write("Preview of the uploaded points data:")
188
  st.dataframe(locations_df.head())
189
 
190
- # Create a LeafMap object to display the points
191
- m = leafmap.Map(center=[locations_df['latitude'].mean(), locations_df['longitude'].mean()], zoom=10)
192
-
193
- # Add points to the map
194
- for _, row in locations_df.iterrows():
195
- m.add_marker(location=[row['latitude'], row['longitude']], popup=row.get('name', 'No Name'))
196
-
197
- # Display map
198
- st.write("Map of Uploaded Points:")
199
- m.to_streamlit()
200
-
201
- # Store the map in session_state
202
- st.session_state.map_data = m
203
-
204
- if polygons_df is not None:
205
- # Display a preview of the polygons data
206
- st.write("Preview of the uploaded polygons data:")
207
- st.dataframe(polygons_df.head())
208
-
209
- # Create a LeafMap object to display the polygons
210
- m = leafmap.Map(center=[polygons_df.geometry.centroid.y.mean(), polygons_df.geometry.centroid.x.mean()], zoom=4)
211
 
212
- # Plot polygons on the map
213
- for _, row in polygons_df.iterrows():
214
- m.add_geojson(geojson=row['geometry'].__geo_interface__)
215
 
216
- # Display map
217
- st.write("Map of Uploaded Polygons:")
218
- m.to_streamlit()
219
 
220
- # Store the map in session_state
221
- st.session_state.map_data = m
222
 
223
  # Process each point
224
- if locations_df is not None:
225
  for idx, row in locations_df.iterrows():
226
- latitude = row['latitude']
227
- longitude = row['longitude']
228
  location_name = row.get('name', f"Location_{idx}")
229
- # st.write(f"Processing {location_name} (Lat: {latitude}, Lon: {longitude})")
230
 
231
  # Define the region of interest (ROI)
232
  roi = ee.Geometry.Point([longitude, latitude])
@@ -261,17 +257,15 @@ if file_upload:
261
  if result:
262
  # Extract just the numeric value, not the dictionary with 'NDVI' label
263
  calculated_value = result.getInfo()
264
- # Display the result as a numeric value, not as a dictionary
265
- # st.write(f"Result for {location_name}: {calculated_value['NDVI'] if 'NDVI' in calculated_value else calculated_value}")
266
-
267
  # Store the result in session state
268
  st.session_state.results.append({
269
  'Location Name': location_name,
270
  'Latitude': latitude,
271
  'Longitude': longitude,
272
- 'Calculated Value': calculated_value['NDVI'] if 'NDVI' in calculated_value else calculated_value # Only store the numeric value
273
  })
274
 
 
275
  # Generate the dynamic filename
276
  filename = f"{main_selection}_{sub_selection}_{start_date.strftime('%Y/%m/%d')}_{end_date.strftime('%Y/%m/%d')}_{shape_type}.csv"
277
 
 
182
  else:
183
  st.error("Unsupported file type. Please upload a GeoJSON or KML file for polygons.")
184
 
185
+ # Display a preview of the dataframe
186
  if locations_df is not None:
 
187
  st.write("Preview of the uploaded points data:")
188
  st.dataframe(locations_df.head())
189
 
190
+ # Check column names in the uploaded data
191
+ st.write("Column names in the uploaded data:", locations_df.columns)
192
+
193
+ # Check for latitude and longitude columns in different cases
194
+ latitude_column = None
195
+ longitude_column = None
196
+
197
+ for col in locations_df.columns:
198
+ if 'lat' in col.lower():
199
+ latitude_column = col
200
+ if 'lon' in col.lower() or 'long' in col.lower():
201
+ longitude_column = col
202
+
203
+ if latitude_column is None or longitude_column is None:
204
+ st.error("Latitude and/or Longitude columns not found in the uploaded file. Please make sure the data includes these columns.")
205
+ else:
206
+ # Create a LeafMap object to display the points
207
+ m = leafmap.Map(center=[locations_df[latitude_column].mean(), locations_df[longitude_column].mean()], zoom=10)
 
 
 
208
 
209
+ # Add points to the map
210
+ for _, row in locations_df.iterrows():
211
+ m.add_marker(location=[row[latitude_column], row[longitude_column]], popup=row.get('name', 'No Name'))
212
 
213
+ # Display map
214
+ st.write("Map of Uploaded Points:")
215
+ m.to_streamlit()
216
 
217
+ # Store the map in session_state
218
+ st.session_state.map_data = m
219
 
220
  # Process each point
221
+ if locations_df is not None and latitude_column and longitude_column:
222
  for idx, row in locations_df.iterrows():
223
+ latitude = row[latitude_column]
224
+ longitude = row[longitude_column]
225
  location_name = row.get('name', f"Location_{idx}")
 
226
 
227
  # Define the region of interest (ROI)
228
  roi = ee.Geometry.Point([longitude, latitude])
 
257
  if result:
258
  # Extract just the numeric value, not the dictionary with 'NDVI' label
259
  calculated_value = result.getInfo()
 
 
 
260
  # Store the result in session state
261
  st.session_state.results.append({
262
  'Location Name': location_name,
263
  'Latitude': latitude,
264
  'Longitude': longitude,
265
+ 'Calculated Value': calculated_value
266
  })
267
 
268
+
269
  # Generate the dynamic filename
270
  filename = f"{main_selection}_{sub_selection}_{start_date.strftime('%Y/%m/%d')}_{end_date.strftime('%Y/%m/%d')}_{shape_type}.csv"
271