【问题标题】:Ho can I include many coordinates on a map within a circle with Python?如何使用 Python 在一个圆圈内的地图上包含许多坐标?
【发布时间】:2020-07-15 06:31:40
【问题描述】:

我有一个坐标列表。我可以在地图上画一个简单地覆盖它们的圆圈吗?我正在考虑使用folium 包并绘制一个以平均坐标为中心的圆,其半径为到最远点的距离。然而,事实证明radius 与地图上的实际距离不对应,所以当我放大/缩小时它不会相应地改变。

import folium
import numpy as np
from geopy.distance import geodesic

points = [(39.9756783, 116.3308383),
          (39.9756649, 116.3308749),
          (39.97564, 116.3308749),
          (39.9756533, 116.3308583),
          (39.9756316, 116.3308299)]
center = (np.mean([a for a,b in points]), np.mean([b for a,b in points]))
MAP = folium.Map(location = list(center), zoom_start = 10)
folium.CircleMarker(location = list(center), 
                    radius = max([geodesic(center,point).meters for point in points]),
                    color = '#3186cc', fill = True, fill_color = '#3186cc'
                   ).add_to(MAP)
MAP

当列表太长而无法精确定位每一对坐标时,我真的想粗略地说明它们所属的范围。

【问题讨论】:

    标签: python python-3.x maps folium geopy


    【解决方案1】:

    IIUC,您可以使用Circle(),它让您有机会以米为单位指定半径(请注意,我将最大值乘以 10 以获得更大的圆)。

    例如:

    import folium
    import numpy as np
    from geopy.distance import geodesic
    
    points = [(39.9756783, 116.3308383),
              (39.9756649, 116.3308749),
              (39.97564, 116.3308749),
              (39.9756533, 116.3308583),
              (39.9756316, 116.3308299)]
    center = (np.mean([a for a,b in points]), np.mean([b for a,b in points]))
    MAP = folium.Map(location = list(center), zoom_start = 10)
    
    for p in points:
        folium.Marker(p).add_to(MAP)
    
    folium.Circle(location = list(center),
                        radius = max([geodesic(center,point).meters for point in points])*10,
                        color = '#3186cc',
                        fill = True,
                        fill_color = '#3186cc').add_to(MAP)
    MAP
    

    放大你会得到:

    【讨论】:

    • 非常感谢!这正是我的想法。
    猜你喜欢
    • 2018-10-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-29
    • 2012-11-12
    • 2014-07-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多