drawers.py 1.2 KB
Newer Older
Q
init  
QinYuan 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
# -*- coding: utf-8 -*-
"""
Created on Sun Mar  4 13:38:00 2018

@author: 燃烧杯
"""


def draw_locations(locations, fileName, path="./"):
    import pandas as pd
    if not isinstance(locations, pd.DataFrame):
        from .exceptions import InputTypeNotSuportException
        raise InputTypeNotSuportException(InputTypeNotSuportException.input_type)
    if "省" not in locations.columns or "市" not in locations.columns \
         or "区" not in locations.columns:
        raise InputTypeNotSuportException(InputTypeNotSuportException.input_type)
    import folium
    from folium.plugins import HeatMap
    from .infrastructure import SuperMap
    map_keys = locations["省"] + "," + locations["市"] + "," + locations["区"]
    heatData = []
    for map_key in map_keys:
        if SuperMap.lat_lon_mapper.get(map_key):
            lat_lon = SuperMap.lat_lon_mapper[map_key]
            heatData.append([lat_lon[0], lat_lon[1], 1])
    map_osm = folium.Map(location=[35,110],zoom_start=5)    #绘制Map,开始缩放程度是5倍
    HeatMap(heatData).add_to(map_osm)  # 将热力图添加到前面建立的map里
    file_path = path + fileName
    map_osm.save(file_path) #保存为html文件