【python】使用folium可视化地理数据

高德底图创建地图对象

import folium
pointsList = [[22.760371, 114.653769], [22.760371, 114.653269]]
tiles_gd = r"http://wprd04.is.autonavi.com/appmaptile?lang=zh_cn&size=1&style=7&x={x}&y={y}&z={z}"
test_map = folium.folium.Map(location=pointsList[0], tiles=tiles_gd, attr="default", zoom_start=13, tooltip="click me!")

添加点数据

for i, it in enumerate(pointsList):
    folium.Marker(it, popup='Mt. Hood Meadows',).add_to(test_map)

添加线数据

tmp_line = [[22.760371, 114.651769], [22.791271, 114.634176], [22.8004471, 114.651176]]
folium.PolyLine(locations=tmp_line, color="red").add_to(test_map)

添加面数据

tmp_polygon = [[22.734037, 114.651769], [22.761117, 114.634176], [22.762244, 114.651176],[22.734037, 114.651769]]
folium.Polygon(locations=tmp_polygon, fill_color='red').add_to(test_map)

点击位置显示经纬度

test_map.add_child(folium.LatLngPopup())

点击生成标记

test_map.add_child(folium.ClickForMarker(popup="Waypoint"))

保存地图

test_map.save(r"/Users/Learn/result/test.html")

注意加载高德瓦片一定要有attr="default”!!!
可视化结果.

此外,还可以

  • 将json作为弹窗
  • 加载json格式的地理数据
  • 绘制分布图
  • 自定义图例
    ……

更多可参考用户手册:
https://python-visualization.github.io/folium/quickstart.html#Markers

你可能感兴趣的:(【python】使用folium可视化地理数据)