{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "0.8.3+52.g2758dc7.dirty\n" ] } ], "source": [ "import os\n", "import folium\n", "\n", "print(folium.__version__)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Using Leaflet's Smooth Factor Option\n", "\n", "[Polyline](http://leafletjs.com/reference.html#polyline) objects in leaflet are smoothed by default. This removes points from the line, putting less load on the browser when drawing. The level of smoothing [can be specified](http://leafletjs.com/reference.html#polyline-smoothfactor) by passing `smoothFactor` as an option when creating any Polyline object.\n", "\n", "In folium, the level of smoothing 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." ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "scrolled": false }, "outputs": [ { "data": { "text/html": [ "
" ], "text/plain": [ "" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import json\n", "import requests\n", "\n", "\n", "m = folium.Map(\n", " location=[-59.1759, -11.6016],\n", " tiles='Mapbox Bright',\n", " zoom_start=2\n", ")\n", "\n", "\n", "url = 'https://raw.githubusercontent.com/python-visualization/folium/master/examples/data'\n", "fname = f'{url}/antarctic_ice_shelf_topo.json'\n", "topo = json.loads(requests.get(fname).text)\n", "\n", "\n", "folium.TopoJson(\n", " data=topo,\n", " object_path='objects.antarctic_ice_shelf',\n", " name='default_smoothing',\n", " smooth_factor=1,\n", " style_function=lambda x: {'color': '#004c00', 'opacity': '0.7'},\n", ").add_to(m)\n", "\n", "\n", "folium.TopoJson(\n", " data=topo,\n", " object_path='objects.antarctic_ice_shelf',\n", " name='default_smoothing',\n", " smooth_factor=10,\n", " style_function=lambda x: {'color': '#1d3060', 'opacity': '0.7'},\n", ").add_to(m)\n", "\n", "folium.LayerControl().add_to(m)\n", "\n", "m.save(os.path.join('results', 'SmoothFactor.html'))\n", "\n", "m" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.3" } }, "nbformat": 4, "nbformat_minor": 1 }