绘制封闭且填充的轮廓

Draw a closed and filled contour

我正在尝试绘制一个封闭的轮廓并用 folium 填充(透明或其他)颜色。缺少文档没有帮助,有什么想法吗?

这是我当前的代码

m = folium.Map(location=[46, 2], zoom_start=5)

pts = [
[43.601795137863135, 1.451673278566412],
[43.61095574264419, 1.437239509310642],
[43.60999839038903, 1.45630473303456],
[43.60607351937904, 1.438762676051137],
[43.59725521090158, 1.444569790831369],
[43.6076281683173, 1.451991362348086]
]

p = folium.PolyLine(locations=pts,weight=5)
m.add_children(p)

这没有记录(没有真正记录 ATM),但它有效

m = folium.Map(location=[46, 2], zoom_start=5)

pts = [
[43.601795137863135, 1.451673278566412],
[43.61095574264419, 1.437239509310642],
[43.60999839038903, 1.45630473303456],
[43.60607351937904, 1.438762676051137],
[43.59725521090158, 1.444569790831369],
[43.6076281683173, 1.451991362348086]
]

folium.features.PolygonMarker(locations=pts, color='#FF0000', fill_color='blue', weight=5).add_to(m)

要添加到Overdrivr的代码中,您还可以先制作点的凸包来确定点覆盖的区域。

from scipy.spatial import ConvexHull
import folium

m = folium.Map(location=[43.6, 1.43], zoom_start=13)

pts = [
[43.601795137863135, 1.451673278566412],
[43.61095574264419, 1.437239509310642],
[43.60999839038903, 1.45630473303456],
[43.60607351937904, 1.438762676051137],
[43.59725521090158, 1.444569790831369],
[43.6076281683173, 1.451991362348086]
]

b = [pts[i] for i in ConvexHull(pts).vertices]

folium.features.PolygonMarker(locations=b, color='#FF0000', fill_color='blue', weight=5).add_to(m)