Python使用folium excel繪制point
使用folium excel 繪制point
制作內(nèi)容
- 根據(jù)氣象臺(tái)資料獲得的點(diǎn)進(jìn)行繪制
- 對(duì)一個(gè)特殊的點(diǎn)做特別的標(biāo)注
- 數(shù)據(jù)來源
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @File : map03.py
# @Author: huifer
# @Date : 2018/6/28
import pandas as pd
import math
import folium
def degree_conversion_decimal(x):
"""
度分轉(zhuǎn)換成十進(jìn)制
:param x: float
:return: integer float
"""
integer = int(x)
integer = integer + (x - integer) * 1.66666667
return integer
def distance(origin, destination):
"""
經(jīng)緯度計(jì)算兩點(diǎn)距離
: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['觀測(cè)場(chǎng)拔海高度(米)'] = data['觀測(cè)場(chǎng)拔海高度(米)'].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)容對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,謝謝大家對(duì)腳本之家的支持。如果你想了解更多相關(guān)內(nèi)容請(qǐng)查看下面相關(guān)鏈接
- Python利用folium實(shí)現(xiàn)地圖可視化
- Python繪制地圖神器folium的新人入門指南
- python-地圖可視化組件folium的操作
- 利用Python的folium包繪制城市道路圖的實(shí)現(xiàn)示例
- Python 使用folium繪制leaflet地圖的實(shí)現(xiàn)方法
- python使用folium庫繪制地圖點(diǎn)擊框
- Python 線程池模塊之多線程操作代碼
- Python基礎(chǔ)之logging模塊知識(shí)總結(jié)
- Python協(xié)程asyncio模塊的演變及高級(jí)用法
- Python中zipfile壓縮包模塊的使用
- python process模塊的使用簡介
- Python基礎(chǔ)之元編程知識(shí)總結(jié)
相關(guān)文章
python實(shí)現(xiàn)修改固定模式的字符串內(nèi)容操作示例
這篇文章主要介紹了python實(shí)現(xiàn)修改固定模式的字符串內(nèi)容操作,結(jié)合實(shí)例形式詳細(xì)分析了Python修改固定模式字符串原理、實(shí)現(xiàn)方法及相關(guān)操作注意事項(xiàng),需要的朋友可以參考下2019-12-12
解決Cannot?set?up?a?python?SDK?at?Python問題
本文主要介紹了解決Cannot?set?up?a?python?SDK?at?Python問題,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2025-04-04
Python selenium抓取微博內(nèi)容的示例代碼
本篇文章主要介紹了Python selenium抓取微博內(nèi)容的示例代碼,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2018-05-05
python數(shù)據(jù)結(jié)構(gòu)之鏈表詳解
這篇文章主要為大家詳細(xì)介紹了python數(shù)據(jù)結(jié)構(gòu)之鏈表的相關(guān)資料,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-09-09
Python 實(shí)現(xiàn)數(shù)據(jù)結(jié)構(gòu)-堆棧和隊(duì)列的操作方法
隊(duì)、棧和鏈表一樣,在數(shù)據(jù)結(jié)構(gòu)中非常基礎(chǔ)一種數(shù)據(jù)結(jié)構(gòu),同樣他們也有各種各樣、五花八門的變形和實(shí)現(xiàn)方式。這篇文章主要介紹了Python 實(shí)現(xiàn)數(shù)據(jù)結(jié)構(gòu)-堆棧和隊(duì)列的操作方法,需要的朋友可以參考下2019-07-07
Python?Asyncio?庫之同步原語常用函數(shù)詳解
這篇文章主要為大家介紹了Python?Asyncio?庫之同步原語常用函數(shù)詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-03-03

