30 ธ.ค. 2022 เวลา 10:43 • ยานยนต์
จุดเสี่ยง !!! อุบัติเหตุจราจรใน กทม. (ข้อมูล 23 มีนาคม 2564)
วันหยุด หาจุดเสี่ยงอุบัติเหตุใน กทม. จากข้อมูลเปิด https://opendata.data.go.th/dataset/riskzone (ข้อมูล 23 มีนาคม 2564)
ใช้ python ดึงข้อมูลแล้วนำมา plot ใน map เลยครับ
import requests
import json
import pandas as pd
response = requests.request("GET", url, headers=headers, data=payload)
print(response.text)
# Load the JSON object
data = json.loads(response.text)
# Extract the records from the JSON object
records = data['result']['records']
# Create a list to store the latitude and longitude values
coordinates = []
# Loop over the records
for record in records:
# Extract the latitude and longitude values
lat, lon = map(float, record['พิกัด'].split(','))
# Append the values to the list
coordinates.append((lat, lon))
# Create a DataFrame from the list of coordinates
df = pd.DataFrame(coordinates, columns=['latitude', 'longitude'])
df
แสงในแผนที่ด้วย folium
import folium
# Create a Map instance
m = folium.Map(location=None, zoom_start=13)
# Loop over the rows in the DataFrame
for index, row in df.iterrows():
# Add a marker for the row
folium.Marker([row['latitude'], row['longitude']]).add_to(m)
# Display the map
m
พื้นที่ สน.ไหนเหตุเยอะสุด?
บางขุนเทียน 12 เหตุ
ราษฎร์บูรณะ 9 เหตุ
ปัจจุบันคงเปลี่ยนไปแล้ว แต่ยังไม่มี data update
โฆษณา