栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

Python使用folium excel绘制point

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Python使用folium excel绘制point

使用folium excel 绘制point

制作内容

  • 根据气象台资料获得的点进行绘制
  • 对一个特殊的点做特别的标注
  • 数据来源
#!/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):
  """
  度分转换成十进制
  :param x: float
  :return: integer float
  """
  integer = int(x)
  integer = integer + (x - integer) * 1.66666667
  return integer
def distance(origin, destination):
  """
  经纬度计算两点距离
  :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
# 数据准备
data = pd.read_excel('SURF_CHN_MUL_HOR_STATION.xlsx')
# 修改成十进制 以及保留1一位小数
data['经度'] = data['经度'].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('气象站信息十进制.csv')
data["距离杭州(km)"] = data.apply(lambda r: distance((r['纬度'], r['经度']), (30.14, 120.1)), axis=1)
# print(data[data['距离杭州(km)']<100].sort_values('距离杭州(km)'))
# 选择除了杭州以外的内容
selected_st = data[data['距离杭州(km)'] < 100].sort_values('距离杭州(km)').iloc[1::]
# 展示地图
# 提取数据
hzdata = data.ix[data['站名'] == '杭州', ['站名', '纬度', '经度']]
myMap = folium.Map(location=[hzdata.iloc[0]['纬度'], hzdata.iloc[0]['经度']])
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]['经度']],
  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]['经度']
  test = folium.Html(
    'name:{}
x:{}
y:{}
'.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")

成果展示

总结

以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,谢谢大家对考高分网的支持。如果你想了解更多相关内容请查看下面相关链接

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/27668.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号