溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

Python使用folium excel繪制point的方法

發(fā)布時(shí)間:2021-03-30 10:07:48 來源:億速云 閱讀:265 作者:小新 欄目:開發(fā)技術(shù)

這篇文章主要介紹了Python使用folium excel繪制point的方法,具有一定借鑒價(jià)值,感興趣的朋友可以參考下,希望大家閱讀完這篇文章之后大有收獲,下面讓小編帶著大家一起了解一下。

使用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['觀測場拔海高度(米)'] = 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")

成果展示

Python使用folium excel繪制point的方法

感謝你能夠認(rèn)真閱讀完這篇文章,希望小編分享的“Python使用folium excel繪制point的方法”這篇文章對(duì)大家有幫助,同時(shí)也希望大家多多支持億速云,關(guān)注億速云行業(yè)資訊頻道,更多相關(guān)知識(shí)等著你來學(xué)習(xí)!

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI