File size: 1,960 Bytes
a0ba5cc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
be817c3
 
a0ba5cc
 
 
 
 
 
 
 
 
 
 
be817c3
a0ba5cc
 
be817c3
a0ba5cc
be817c3
 
 
 
a0ba5cc
be817c3
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
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 = 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)
m.save("/tmp/location_map.html")

# HTML둜 Streamlit에 μ‹œκ°ν™”
with open("/tmp/location_map.html", "r", encoding="utf-8") as f:
    map_html = f.read()
st.components.v1.html(map_html, height=500)

# 지도 λ‹€μš΄λ‘œλ“œ
st.download_button("μœ„μΉ˜ 지도 λ‹€μš΄λ‘œλ“œ", map_html, file_name="location_map.html")