Spaces:
Sleeping
Sleeping
fschwartzer
commited on
Commit
•
bbe788d
1
Parent(s):
7da2b98
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import pandas as pd
|
3 |
+
import numpy as np
|
4 |
+
from geopy.distance import geodesic
|
5 |
+
|
6 |
+
# Create a DataFrame with sample data
|
7 |
+
data = pd.DataFrame({
|
8 |
+
'lat': np.random.uniform(-90, 90, 1000),
|
9 |
+
'lon': np.random.uniform(-180, 180, 1000),
|
10 |
+
'value': np.random.rand(1000) * 100
|
11 |
+
})
|
12 |
+
|
13 |
+
# Function to calculate distance in meters between two coordinates
|
14 |
+
def calculate_distance(lat1, lon1, lat2, lon2):
|
15 |
+
coords_1 = (lat1, lon1)
|
16 |
+
coords_2 = (lat2, lon2)
|
17 |
+
return geodesic(coords_1, coords_2).meters
|
18 |
+
|
19 |
+
# Display a title
|
20 |
+
st.title('Geospatial Dashboard')
|
21 |
+
|
22 |
+
# Dropdown to select specific coordinates
|
23 |
+
selected_coords = st.selectbox('Select Coordinates', ['Random', 'Custom'])
|
24 |
+
if selected_coords == 'Custom':
|
25 |
+
custom_lat = st.number_input('Enter Latitude', value=0.0)
|
26 |
+
custom_lon = st.number_input('Enter Longitude', value=0.0)
|
27 |
+
else:
|
28 |
+
custom_lat, custom_lon = 0.0, 0.0
|
29 |
+
|
30 |
+
# Slider for setting the zoom level
|
31 |
+
zoom_level = st.slider('Zoom Level', min_value=1, max_value=15, value=5)
|
32 |
+
|
33 |
+
# Slider to set the radius in meters
|
34 |
+
radius_in_meters = st.slider('Select Radius (in meters)', min_value=100, max_value=5000, value=1000)
|
35 |
+
|
36 |
+
# Filter data based on the radius
|
37 |
+
if selected_coords == 'Custom':
|
38 |
+
filtered_data = data[data.apply(lambda x: calculate_distance(x['lat'], x['lon'], custom_lat, custom_lon), axis=1) <= radius_in_meters]
|
39 |
+
st.map(filtered_data, zoom=zoom_level, use_container_width=True)
|
40 |
+
else:
|
41 |
+
st.map(data, zoom=zoom_level, use_container_width=True)
|