使用folium excel 繪制point
制作內(nèi)容
#!/usr/bin/env python# -*- coding: utf-8 -*-# @File : map03.py# @Author: huifer# @Date : 2018/6/28import pandas as pdimport mathimport foliumdef degree_conversion_decimal(x): """ 度分轉(zhuǎn)換成十進(jìn)制 :param x: float :return: integer float """ integer = int(x) integer = integer + (x - integer) * 1.66666667 return integerdef distance(origin, destination): """ 經(jīng)緯度計算兩點距離 :param origin: :param destination: :return: """ lat1, lon1 = origin lat2, lon2 = destination radius = 6371 # km dlat = math.radians(lat2 - lat1) dlon = math.radians(lon2 - lon1) a = math.sin(dlat / 2) * math.sin(dlat / 2) + math.cos(math.radians(lat1)) / * math.cos(math.radians(lat2)) * math.sin(dlon / 2) * math.sin(dlon / 2) c = 2 * math.atan2(math.sqrt(a), math.sqrt(1 - a)) d = radius * c return d# 數(shù)據(jù)準(zhǔn)備data = pd.read_excel('SURF_CHN_MUL_HOR_STATION.xlsx')# 修改成十進(jìn)制 以及保留1一位小數(shù)data['經(jīng)度'] = data['經(jīng)度'].apply(degree_conversion_decimal)data['緯度'] = data['緯度'].apply(degree_conversion_decimal)data['觀測場拔海高度(米)'] = data['觀測場拔海高度(米)'].apply(lambda x: round(x, 1))data['氣壓傳感器拔海高度(米)'] = data['氣壓傳感器拔海高度(米)'].apply(lambda x: round(x, 1))# 保存新的文件# data.to_csv('氣象站信息十進(jìn)制.csv')data["距離杭州(km)"] = data.apply(lambda r: distance((r['緯度'], r['經(jīng)度']), (30.14, 120.1)), axis=1)# print(data[data['距離杭州(km)']<100].sort_values('距離杭州(km)'))# 選擇除了杭州以外的內(nèi)容selected_st = data[data['距離杭州(km)'] < 100].sort_values('距離杭州(km)').iloc[1::]# 展示地圖# 提取數(shù)據(jù)hzdata = data.ix[data['站名'] == '杭州', ['站名', '緯度', '經(jīng)度']]myMap = folium.Map(location=[hzdata.iloc[0]['緯度'], hzdata.iloc[0]['經(jīng)度']])icon_hz = dict( prefix='fa', color='red', icon_color='darkred', icon='cny')icon = folium.Icon(**icon_hz)folium.Marker( location=[hzdata.iloc[0]['緯度'], hzdata.iloc[0]['經(jīng)度']], popup="杭州", icon=icon).add_to(myMap)for i in range(len(selected_st)): name = selected_st.iloc[i]['站名'] x = selected_st.iloc[i]['緯度'] y = selected_st.iloc[i]['經(jīng)度'] test = folium.Html( '<b>name:{}</b></br> <b>x:{}</b></br> <b>y:{}</b></br>'.format(name, x, y), script=True) popup = folium.Popup(test, max_width=2650) folium.Marker( location=[x, y], popup=popup, ).add_to(myMap)myMap.save("test.html")成果展示

總結(jié)
以上就是這篇文章的全部內(nèi)容了,希望本文的內(nèi)容對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,謝謝大家對VEVB武林網(wǎng)的支持。
新聞熱點
疑難解答
圖片精選