Files changed (1) hide show
  1. app.py +71 -0
app.py ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from geopy.geocoders import Nominatim
3
+ import pandas as pd
4
+ import folium
5
+ from folium.plugins import HeatMap
6
+ from geopy.distance import geodesic
7
+ import numpy as np
8
+ import warnings
9
+
10
+ # 경고 메시지를 무시하기
11
+ warnings.filterwarnings("ignore", category=UserWarning, module="geopy")
12
+
13
+ # Geolocator 설정
14
+ geolocator = Nominatim(user_agent="hwaseong_locator")
15
+
16
+ # 위도와 경도를 주소로 변환하는 함수
17
+ def get_location_name(lat, lon):
18
+ location = geolocator.reverse((lat, lon), language='ko')
19
+ return location.address if location else "주소를 찾을 수 없음"
20
+
21
+ # 위험도 분류 함수
22
+ def classify_risk(score):
23
+ if score >= 2:
24
+ return "매우 안전"
25
+ elif 1 <= score < 2:
26
+ return "안전"
27
+ elif 0 <= score < 1:
28
+ return "보통"
29
+ elif -1 < score < 0:
30
+ return "위험"
31
+ else:
32
+ return "매우 위험"
33
+
34
+ # 화성시 중심 좌표
35
+ hwaseong_center = [37.198, 127.034]
36
+
37
+ # 사용자 입력을 받기
38
+ st.title("화성시 위치 위험도 분석기")
39
+
40
+ lat_input = st.number_input("위도 (Latitude)", value=37.198, format="%.6f")
41
+ lon_input = st.number_input("경도 (Longitude)", value=127.034, format="%.6f")
42
+
43
+ # 실제 주소 확인
44
+ location_name = get_location_name(lat_input, lon_input)
45
+ st.write(f"위치: {location_name}")
46
+
47
+ # 예시 데이터 (간단히 정해둔 예시입니다. 실제로는 이 데이터를 기반으로 계산합니다.)
48
+ sample_scores = {
49
+ (37.198, 127.034): 3, # 예시 안전 지역
50
+ (37.198, 127.035): -2, # 예시 위험 지역
51
+ }
52
+
53
+ # 해당 위치에 대한 점수 찾기
54
+ def get_score_for_location(lat, lon):
55
+ closest_location = min(sample_scores.keys(), key=lambda x: geodesic((lat, lon), x).meters)
56
+ return sample_scores[closest_location]
57
+
58
+ score = get_score_for_location(lat_input, lon_input)
59
+ risk_category = classify_risk(score)
60
+
61
+ st.write(f"위험도: {risk_category}")
62
+
63
+ # 지도 표시
64
+ m = folium.Map(location=[lat_input, lon_input], zoom_start=16)
65
+ folium.Marker([lat_input, lon_input], popup=location_name).add_to(m)
66
+
67
+ # 결과를 HTML로 저장
68
+ m.save("location_map.html")
69
+
70
+ # 다운로드 링크
71
+ st.download_button("위치 지도 다운로드", "location_map.html")