import streamlit as st from geopy.geocoders import Nominatim import pandas as pd import folium from folium.plugins import HeatMap from geopy.distance import geodesic import numpy as np import warnings # 경고 메시지를 무시하기 warnings.filterwarnings("ignore", category=UserWarning, module="geopy") # Geolocator 설정 geolocator = Nominatim(user_agent="hwaseong_locator") # 위도와 경도를 주소로 변환하는 함수 def get_location_name(lat, lon): location = geolocator.reverse((lat, lon), language='ko') return location.address if location else "주소를 찾을 수 없음" # 위험도 분류 함수 def classify_risk(score): if score >= 2: return "매우 안전" elif 1 <= score < 2: return "안전" elif 0 <= score < 1: return "보통" elif -1 < score < 0: return "위험" else: return "매우 위험" # 화성시 중심 좌표 hwaseong_center = [37.198, 127.034] # 사용자 입력을 받기 st.title("화성시 위치 위험도 분석기") lat_input = st.number_input("위도 (Latitude)", value=37.198, format="%.6f") lon_input = st.number_input("경도 (Longitude)", value=127.034, format="%.6f") # 실제 주소 확인 location_name = get_location_name(lat_input, lon_input) st.write(f"위치: {location_name}") # 예시 데이터 (간단히 정해둔 예시입니다. 실제로는 이 데이터를 기반으로 계산합니다.) sample_scores = { (37.198, 127.034): 3, # 예시 안전 지역 (37.198, 127.035): -2, # 예시 위험 지역 } # 해당 위치에 대한 점수 찾기 def get_score_for_location(lat, lon): closest_location = min(sample_scores.keys(), key=lambda x: geodesic((lat, lon), x).meters) return sample_scores[closest_location] score = get_score_for_location(lat_input, lon_input) risk_category = classify_risk(score) st.write(f"위험도: {risk_category}") # 지도 표시 m = folium.Map(location=[lat_input, lon_input], zoom_start=16) folium.Marker([lat_input, lon_input], popup=location_name).add_to(m) # 결과를 HTML로 저장 m.save("location_map.html") # 다운로드 링크 st.download_button("위치 지도 다운로드", "location_map.html")