Spaces:
Running
Running
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import folium
|
| 4 |
+
from streamlit_folium import st_folium
|
| 5 |
+
from streamlit_js_eval import get_geolocation
|
| 6 |
+
import time
|
| 7 |
+
|
| 8 |
+
# تنظیمات صفحه
|
| 9 |
+
st.set_page_config(page_title="برداشت مسیر فیبر نوری", layout="wide")
|
| 10 |
+
|
| 11 |
+
st.title("📍 سامانه ثبت مسیر و نقاط پروژه")
|
| 12 |
+
st.write("ابتدا اجازه دسترسی به GPS را در مرورگر تایید کنید.")
|
| 13 |
+
|
| 14 |
+
# ایجاد حافظه موقت برای ذخیره نقاط
|
| 15 |
+
if 'points' not in st.session_state:
|
| 16 |
+
st.session_state.points = []
|
| 17 |
+
|
| 18 |
+
# دریافت موقعیت لحظهای از مرورگر
|
| 19 |
+
location = get_geolocation()
|
| 20 |
+
|
| 21 |
+
col1, col2 = st.columns([1, 3])
|
| 22 |
+
|
| 23 |
+
with col1:
|
| 24 |
+
st.subheader("کنترل")
|
| 25 |
+
|
| 26 |
+
if location:
|
| 27 |
+
lat = location['coords']['latitude']
|
| 28 |
+
lon = location['coords']['longitude']
|
| 29 |
+
acc = location['coords']['accuracy']
|
| 30 |
+
|
| 31 |
+
st.success(f"موقعیت یافت شد!\nدقت: {acc} متر")
|
| 32 |
+
st.info(f"Lat: {lat}\nLon: {lon}")
|
| 33 |
+
|
| 34 |
+
if st.button("📌 ثبت نقطه (باکس/تقاطع)", use_container_width=True):
|
| 35 |
+
new_point = {
|
| 36 |
+
"time": time.strftime("%H:%M:%S"),
|
| 37 |
+
"lat": lat,
|
| 38 |
+
"lon": lon,
|
| 39 |
+
"acc": acc
|
| 40 |
+
}
|
| 41 |
+
st.session_state.points.append(new_point)
|
| 42 |
+
st.toast("نقطه با موفقیت ثبت شد")
|
| 43 |
+
else:
|
| 44 |
+
st.warning("در حال دریافت سیگنال GPS... (مطمئن شوید Location گوشی روشن است)")
|
| 45 |
+
|
| 46 |
+
if st.button("🗑️ پاکسازی کل مسیر", type="primary", use_container_width=True):
|
| 47 |
+
st.session_state.points = []
|
| 48 |
+
st.rerun()
|
| 49 |
+
|
| 50 |
+
# نمایش لیست نقاط ثبت شده
|
| 51 |
+
if st.session_state.points:
|
| 52 |
+
st.write("---")
|
| 53 |
+
st.write("نقاط ثبت شده:")
|
| 54 |
+
df = pd.DataFrame(st.session_state.points)
|
| 55 |
+
st.dataframe(df[["time", "lat", "lon"]], hide_index=True)
|
| 56 |
+
|
| 57 |
+
with col2:
|
| 58 |
+
# رسم نقشه
|
| 59 |
+
# مرکز نقشه بر اساس آخرین نقطه یا مختصات پیشفرض تهران
|
| 60 |
+
center_lat = st.session_state.points[-1]['lat'] if st.session_state.points else 35.6892
|
| 61 |
+
center_lon = st.session_state.points[-1]['lon'] if st.session_state.points else 51.3890
|
| 62 |
+
|
| 63 |
+
m = folium.Map(location=[center_lat, center_lon], zoom_start=18)
|
| 64 |
+
|
| 65 |
+
# رسم نقاط و خطوط
|
| 66 |
+
path_coords = []
|
| 67 |
+
for p in st.session_state.points:
|
| 68 |
+
path_coords.append([p['lat'], p['lon']])
|
| 69 |
+
folium.CircleMarker(
|
| 70 |
+
location=[p['lat'], p['lon']],
|
| 71 |
+
radius=5,
|
| 72 |
+
color='red',
|
| 73 |
+
fill=True,
|
| 74 |
+
popup=f"Time: {p['time']}"
|
| 75 |
+
).add_to(m)
|
| 76 |
+
|
| 77 |
+
# وصل کردن نقاط به هم با خط
|
| 78 |
+
if len(path_coords) > 1:
|
| 79 |
+
folium.PolyLine(path_coords, color="blue", weight=3, opacity=0.8).add_to(m)
|
| 80 |
+
|
| 81 |
+
# نمایش نقشه
|
| 82 |
+
st_folium(m, width="100%", height=600, key="map")
|
| 83 |
+
|
| 84 |
+
# امکان دانلود خروجی ساده
|
| 85 |
+
if st.session_state.points:
|
| 86 |
+
csv = pd.DataFrame(st.session_state.points).to_csv(index=False).encode('utf-8')
|
| 87 |
+
st.download_button("📥 دانلود فایل CSV نقاط", csv, "survey_points.csv", "text/csv")
|