update app.py
Browse files
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 |
-
#
|
191 |
-
|
192 |
-
|
193 |
-
#
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
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 |
-
|
213 |
-
|
214 |
-
|
215 |
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
|
220 |
-
|
221 |
-
|
222 |
|
223 |
# Process each point
|
224 |
-
if locations_df is not None:
|
225 |
for idx, row in locations_df.iterrows():
|
226 |
-
latitude = row[
|
227 |
-
longitude = row[
|
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
|
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 |
|