Overdrivr
Overdrivr

Reputation: 6596

Draw a closed and filled contour

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)

Upvotes: 0

Views: 1957

Answers (2)

Dick van Huizen
Dick van Huizen

Reputation: 191

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)

Upvotes: 0

Overdrivr
Overdrivr

Reputation: 6596

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)

Upvotes: 1

Related Questions