Smoothing#
The level of smoothing of the geometry can be determined by passing smooth_factor as an argument when initialising GeoJson, TopoJson and Choropleth objects. There are no upper or lower bounds to the smoothing level; Leaflet’s default is 1.
[2]:
import requests
m = folium.Map(location=[-59.1759, -11.6016], tiles="cartodbpositron", zoom_start=2)
topo = requests.get(
"https://raw.githubusercontent.com/python-visualization/folium-example-data/main/antarctic_ice_shelf_topo.json"
).json()
folium.TopoJson(
data=topo,
object_path="objects.antarctic_ice_shelf",
name="default_smoothing",
smooth_factor=1,
style_function=lambda x: {"color": "#004c00", "opacity": "0.7"},
).add_to(m)
folium.TopoJson(
data=topo,
object_path="objects.antarctic_ice_shelf",
name="heavier smoothing",
smooth_factor=10,
style_function=lambda x: {"color": "#1d3060", "opacity": "0.7"},
).add_to(m)
folium.LayerControl().add_to(m)
m
/home/runner/work/folium/folium/folium/raster_layers.py:128: UserWarning: CartoDB tiles now require an API key. Please provide one to continue using the tiles. You can request the key at https://carto.com/basemaps/apikey/.
tiles = tiles.build_url(fill_subdomain=False, scale_factor="{r}") # type: ignore
[2]:
Make this Notebook Trusted to load map: File -> Trust Notebook