Spaces:
Runtime error
Runtime error
File size: 2,984 Bytes
063325f 34a78eb 063325f 34a78eb |
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 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
import gradio as gr
import plotly.graph_objects as go
import json
from shapely.geometry import Point, Polygon
with open('./dnp_bnd.geojson', 'r') as file:
dnp_area = json.load(file)
with open('./nrf_bnd.geojson', 'r') as file:
nrf_area = json.load(file)
def check_area(lat, lon, area):
# Create a Point
point = Point(lon, lat)
# Function to check if point is in any polygon
def is_point_in_any_polygon(point, geojson_data):
for feature in geojson_data['features']:
polygon = Polygon(feature['geometry']['coordinates'][0][0])
if point.within(polygon):
return True
return False
# Check if the point is in the polygon
return is_point_in_any_polygon(point, area)
def filter_map(lat, lon):
is_in_dnp = check_area(lat, lon, dnp_area)
is_in_nrf = check_area(lat, lon, nrf_area)
print(is_in_dnp)
print(is_in_nrf)
if is_in_dnp and not is_in_nrf:
text = 'อยู่ในขอบเขตป่าตามกฎ EUDR'
elif not is_in_dnp and is_in_nrf:
text = 'อยู่ในขอบเขตป่าตามกฎหมายไทย'
elif is_in_dnp and is_in_nrf:
text = 'อยู่ในขอบเขตป่าตามกฎหมายไทยและกฎ EUDR'
else:
text = 'ไม่อยู่ในขอบเขตป่า'
fig = go.Figure(go.Scattermapbox(
# customdata=text_list,
lat=[lat],
lon=[lon],
mode='markers',
marker=go.scattermapbox.Marker(
size=13
),
hoverinfo="text",
hovertemplate=f'<b>ตำแหน่ง</b>: {lat},{lon}<br><b></b>สถานะตำแหน่ง: {text}'
))
# fig.update_layout(
# mapbox_style="open-street-map",
# hovermode='closest',
# mapbox=dict(
# bearing=0,
# center=go.layout.mapbox.Center(
# lat=lat,
# lon=lon
# ),
# pitch=0,
# zoom=9
# ),
# )
fig.update_layout(
mapbox={
'style':"open-street-map",
'center': go.layout.mapbox.Center(
lat=lat,
lon=lon
),
'zoom': 9,
'layers':[
{'sourcetype': 'geojson',
'source': dnp_area['features']},
]
},
)
return fig
with gr.Blocks() as demo:
with gr.Column():
with gr.Row():
lat = gr.Number(value=9.00, label="ละจิจูด")
lon = gr.Number(value=99.076, label="ลองจิจูด")
btn = gr.Button(value="ค้นหาตำแหน่ง")
map = gr.Plot()
demo.load(filter_map, [lat, lon], map)
btn.click(filter_map, [lat, lon], map)
if __name__ == "__main__":
demo.launch()
|