GEO_DASH_TABS / app.py
fschwartzer's picture
Update app.py
643a822
raw
history blame
2.12 kB
import streamlit as st
import pandas as pd
import numpy as np
import openpyxl
from geopy.distance import geodesic
# Create a DataFrame with sample data
data = pd.read_excel('ven_ter_fim_PEDÓ.xlsx')
# Function to calculate distance in meters between two coordinates
def calculate_distance(lat1, lon1, lat2, lon2):
coords_1 = (lat1, lon1)
coords_2 = (lat2, lon2)
return geodesic(coords_1, coords_2).meters
# Find the maximum distance between coordinates
max_distance = 0
for index, row in data.iterrows():
distance = calculate_distance(row['latitude'], row['longitude'], data['latitude'].mean(), data['longitude'].mean())
if distance > max_distance:
max_distance = distance
# Calculate a zoom level based on the maximum distance
zoom_level = 15 - np.log10(max_distance / 25000)
# Create a sidebar for controls
with st.sidebar:
# Display a title
st.title('avalia.se')
# Dropdown to select specific coordinates
selected_coords = st.selectbox('Selecione Coordenadas', ['Random', 'Custom'])
if selected_coords == 'Custom':
custom_lat = st.number_input('Enter Latitude', value=0.0)
custom_lon = st.number_input('Enter Longitude', value=0.0)
else:
custom_lat, custom_lon = data['latitude'].mean(), data['longitude'].mean()
# Slider for setting the zoom level
zoom_level = st.slider('Nível de zoom', min_value=1, max_value=15, value=zoom_level)
# Slider to set the radius in meters
radius_in_meters = st.slider('Selecione raio (em metros)', min_value=100, max_value=5000, value=1000)
# Filter data based on the radius
if selected_coords == 'Custom':
filtered_data = data[data.apply(lambda x: calculate_distance(x['latitude'], x['longitude'], custom_lat, custom_lon), axis=1) <= radius_in_meters]
else:
filtered_data = data
# Add a custom CSS class to the map container
st.markdown(f"""<style>
.map {{
width: 100%;
height: 100vh;
}}
</style>""", unsafe_allow_html=True)
# Wrap the map in a container with the custom CSS class
with st.container():
st.map(filtered_data, zoom=zoom_level, use_container_width=True)