• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

python通过批量经纬度生成标记地图生成

武飞扬头像
lele198838683
帮助3

python通过批量经纬度生成标记地图生成

通过读取excel文件中经纬度数据生成定位图

  1.  
    from pyecharts.charts import Geo
  2.  
    from pyecharts import options as opts
  3.  
    from pyecharts.globals import GeoType
  4.  
    import pandas as pd
  5.  
     
  6.  
     
  7.  
    def mapa():
  8.  
    city = 'xx区县'
  9.  
    g = Geo(init_opts=opts.InitOpts(width='1850px', height='850px'))
  10.  
    g.add_schema(maptype=city)
  11.  
    # 定义坐标对应的名称,添加到坐标库中 add_coordinate(name, lng, lat)
  12.  
    # 导入excel表举例
  13.  
    df = pd.read_excel("学校机构经纬度表.xlsx")
  14.  
    df.head()
  15.  
    # 导入自定义的地点经纬度
  16.  
    for i in range(len(df)):
  17.  
    if isinstance(df.iloc[i]['经度'], float):
  18.  
    g.add_coordinate(df.iloc[i]['机构名称'], df.iloc[i]['经度'], df.iloc[i]['纬度'])
  19.  
    print(df.iloc[i]['机构名称'], df.iloc[i]['经度'], df.iloc[i]['纬度'])
  20.  
    # data_pair= [(df.iloc[i]['机构名称'], int(df.iloc[i]['学校类型编号']))]
  21.  
    data_pair = [(df.iloc[i]['机构名称'], int(df.iloc[i]['学校类型编号'])) for i in range(len(df)) if
  22.  
    isinstance(df.iloc[i]['经度'], float)]
  23.  
     
  24.  
    # 定义数据对,
  25.  
    # 将数据添加到地图上
  26.  
    g.add('学校地图', data_pair, type_=GeoType.EFFECT_SCATTER, symbol_size=3)
  27.  
    # 设置样式
  28.  
    g.set_series_opts(label_opts=opts.LabelOpts(is_show=True, formatter='{b}'))
  29.  
    # 自定义分段 color 可以用取色器取色
  30.  
    pieces = [
  31.  
    {'min': 110, 'max': 111, 'label': '幼儿园', 'color': '#FF0000'}, # 红色
  32.  
    {'min': 210, 'max': 211, 'label': '小学', 'color': '#FF8C00'}, # 橙色
  33.  
    {'min': 217, 'max': 218, 'label': '小学教学点', 'color': '#FF8C66'}, # 橙色
  34.  
    {'min': 310, 'max': 311, 'label': '初级中学', 'color': '#00CED1'}, # 绿色
  35.  
    {'min': 312, 'max': 313, 'label': '九年一贯制', 'color': '#55CED1'}, # 绿色
  36.  
    {'min': 340, 'max': 341, 'label': '完全中学', 'color': '#99CED2'}, # 绿色
  37.  
    {'min': 342, 'max': 343, 'label': '高级中学', 'color': '#22CED6'}, # 绿色
  38.  
    {'min': 363, 'max': 364, 'label': '职业高中', 'color': '#2200FF'},
  39.  
    {'min': 512, 'max': 514, 'label': '特殊教育', 'color': '#0066FF'},
  40.  
    {'min': 410, 'max': 415, 'label': '高等学校', 'color': '#6600FF'} # 蓝色
  41.  
    ]
  42.  
    # is_piecewise 是否自定义分段, 变为true 才能生效
  43.  
    g.set_global_opts(
  44.  
    visualmap_opts=opts.VisualMapOpts(is_piecewise=True, pieces=pieces),
  45.  
    title_opts=opts.TitleOpts(title="{}-学校分布".format(city)), )
  46.  
     
  47.  
    # g = test_geo()
  48.  
    # 渲染成html, 可用浏览器直接打开
  49.  
    g.render_notebook()
  50.  
    g.render("a.html")
  51.  
     
  52.  
    mapa()
学新通

学新通

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /boutique/detail/tanhekkbkk
系列文章
更多 icon
同类精品
更多 icon
继续加载