繁体   English   中英

如何在 Python 的圆圈内包含 map 上的许多坐标?

[英]How can I include many coordinates on a map within a circle with Python?

我有一个坐标列表。 我可以在 map 上画一个短暂覆盖它们的圆圈吗? 我正在考虑使用大folium package 并绘制一个以平均坐标为中心的圆,其半径为最远点的距离。 但是,事实证明radius与 map 上的实际距离不对应,因此当我放大/缩小时它不会相应改变。

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

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

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

放大你会得到:

在此处输入图像描述

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM