0

I am trying to draw a closed contour an fill it up with (transparent or whatever) color with folium. The lacking docs are not helpful, any ideas how to do that ?

This is my current code

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)
Overdrivr
  • 6,296
  • 5
  • 44
  • 70

2 Answers2

1

This is not documented (nothing is really documented ATM), but this works

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
  • 6,296
  • 5
  • 44
  • 70
  • Thanks. Worth noting is that a [LeafLetJs option](https://leafletjs.com/reference-1.6.0.html#path-fillcolor) `fillColor` translates to `fill_color` in python. – Vojta F Mar 30 '21 at 10:29
0

To add to Overdrivr's code, you could also first make the convex hull of the points to determine the area the points cover.

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)
Dick van Huizen
  • 161
  • 1
  • 5