{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "### Circle and CircleMarker" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
Make this Notebook Trusted to load map: File -> Trust Notebook
" ], "text/plain": [ "" ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import folium\n", "from folium.plugins.measure_control import MeasureControl\n", "\n", "m = folium.Map(location=[-27.5717, -48.6256], zoom_start=9)\n", "\n", "c = MeasureControl()\n", "c.add_to(m)\n", "\n", "radius = 50\n", "folium.CircleMarker(\n", " location=[-27.55, -48.8],\n", " radius=radius,\n", " color=\"cornflowerblue\",\n", " stroke=False,\n", " fill=True,\n", " fill_opacity=0.6,\n", " opacity=1,\n", " popup=\"{} pixels\".format(radius),\n", " tooltip=\"I am in pixels\",\n", ").add_to(m)\n", "\n", "radius = 25\n", "folium.CircleMarker(\n", " location=[-27.35, -48.8],\n", " radius=radius,\n", " color=\"black\",\n", " weight=3,\n", " fill=False,\n", " fill_opacity=0.6,\n", " opacity=1,\n", ").add_to(m)\n", "\n", "radius = 10000\n", "folium.Circle(\n", " location=[-27.551667, -48.478889],\n", " radius=radius,\n", " color=\"black\",\n", " weight=1,\n", " fill_opacity=0.6,\n", " opacity=1,\n", " fill_color=\"green\",\n", " fill=False, # gets overridden by fill_color\n", " popup=\"{} meters\".format(radius),\n", " tooltip=\"I am in meters\",\n", ").add_to(m)\n", "\n", "m" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### PolyLine" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
Make this Notebook Trusted to load map: File -> Trust Notebook
" ], "text/plain": [ "" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Coordinates are 15 points on the great circle from Boston to\n", "# San Francisco.\n", "# Reference: http://williams.best.vwh.net/avform.htm#Intermediate\n", "coordinates = [\n", " [42.3581, -71.0636],\n", " [42.82995815, -74.78991444],\n", " [43.17929819, -78.56603306],\n", " [43.40320216, -82.37774519],\n", " [43.49975489, -86.20965845],\n", " [43.46811941, -90.04569087],\n", " [43.30857071, -93.86961818],\n", " [43.02248456, -97.66563267],\n", " [42.61228259, -101.41886832],\n", " [42.08133868, -105.11585198],\n", " [41.4338549, -108.74485069],\n", " [40.67471747, -112.29609954],\n", " [39.8093434, -115.76190821],\n", " [38.84352776, -119.13665678],\n", " [37.7833, -122.4167],\n", "]\n", "\n", "\n", "# Create the map and add the line\n", "m = folium.Map(location=[41.9, -97.3], zoom_start=4)\n", "\n", "folium.PolyLine(\n", " locations=coordinates,\n", " color=\"#FF0000\",\n", " weight=5,\n", " tooltip=\"From Boston to San Francisco\",\n", ").add_to(m)\n", "\n", "folium.PolyLine(\n", " smooth_factor=50,\n", " locations=coordinates,\n", " color=\"grey\",\n", " tooltip=\"Too much smoothing?\",\n", " weight=5,\n", ").add_to(m)\n", "\n", "m" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Dateline" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
Make this Notebook Trusted to load map: File -> Trust Notebook
" ], "text/plain": [ "" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "lon = lat = 0\n", "zoom_start = 1\n", "\n", "m = folium.Map(location=[lat, lon], zoom_start=zoom_start)\n", "\n", "kw = {\"opacity\": 1.0, \"weight\": 6}\n", "folium.PolyLine(\n", " locations=[(2, 179), (2, -179)],\n", " tooltip=\"Wrong\",\n", " color=\"red\",\n", " line_cap=\"round\",\n", " **kw,\n", ").add_to(m)\n", "\n", "\n", "folium.PolyLine(\n", " locations=[(-2, 179), (-2, 181)],\n", " tooltip=\"Correct\",\n", " line_cap=\"butt\",\n", " color=\"blue\",\n", " **kw,\n", ").add_to(m)\n", "\n", "\n", "folium.PolyLine(\n", " locations=[(-6, -179), (-6, 179)],\n", " line_cap=\"square\",\n", " color=\"green\",\n", " tooltip=\"Correct\",\n", " **kw,\n", ").add_to(m)\n", "\n", "\n", "folium.PolyLine(\n", " locations=[(12, -179), (12, 190)],\n", " color=\"orange\",\n", " tooltip=\"Artifact?\",\n", " **kw,\n", ").add_to(m)\n", "\n", "m" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### MultiPolyline" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
Make this Notebook Trusted to load map: File -> Trust Notebook
" ], "text/plain": [ "" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "lat = +38.89399\n", "lon = -77.03659\n", "zoom_start = 17\n", "\n", "m = folium.Map(location=[lat, lon], zoom_start=zoom_start)\n", "\n", "kw = {\"color\": \"red\", \"fill\": True, \"radius\": 20}\n", "\n", "folium.CircleMarker([38.89415, -77.03738], **kw).add_to(m)\n", "folium.CircleMarker([38.89415, -77.03578], **kw).add_to(m)\n", "\n", "\n", "locations = [\n", " [\n", " (38.893596444352134, -77.03814983367920),\n", " (38.893379333722040, -77.03792452812195),\n", " ],\n", " [\n", " (38.893379333722040, -77.03792452812195),\n", " (38.893162222428310, -77.03761339187622),\n", " ],\n", " [\n", " (38.893162222428310, -77.03761339187622),\n", " (38.893028615148424, -77.03731298446655),\n", " ],\n", " [\n", " (38.893028615148424, -77.03731298446655),\n", " (38.892920059048464, -77.03691601753235),\n", " ],\n", " [\n", " (38.892920059048464, -77.03691601753235),\n", " (38.892903358095296, -77.03637957572937),\n", " ],\n", " [\n", " (38.892903358095296, -77.03637957572937),\n", " (38.893011914220770, -77.03592896461487),\n", " ],\n", " [\n", " (38.893011914220770, -77.03592896461487),\n", " (38.893162222428310, -77.03549981117249),\n", " ],\n", " [\n", " (38.893162222428310, -77.03549981117249),\n", " (38.893404384982480, -77.03514575958252),\n", " ],\n", " [\n", " (38.893404384982480, -77.03514575958252),\n", " (38.893596444352134, -77.03496336936950),\n", " ],\n", "]\n", "\n", "folium.PolyLine(\n", " locations=locations,\n", " color=\"orange\",\n", " weight=8,\n", " opacity=1,\n", " smooth_factor=0,\n", ").add_to(m)\n", "\n", "m" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Rectangle" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
Make this Notebook Trusted to load map: File -> Trust Notebook
" ], "text/plain": [ "" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "m = folium.Map(location=[35.685, 139.76], zoom_start=15)\n", "\n", "kw = {\n", " \"color\": \"blue\",\n", " \"line_cap\": \"round\",\n", " \"fill\": True,\n", " \"fill_color\": \"red\",\n", " \"weight\": 5,\n", " \"popup\": \"Tokyo, Japan\",\n", " \"tooltip\": \"Click me!\",\n", "}\n", "\n", "folium.Rectangle(\n", " bounds=[[35.681, 139.766], [35.691, 139.776]],\n", " line_join=\"round\",\n", " dash_array=\"5, 5\",\n", " **kw,\n", ").add_to(m)\n", "\n", "dx = 0.012\n", "folium.Rectangle(\n", " bounds=[[35.681, 139.766 - dx], [35.691, 139.776 - dx]],\n", " line_join=\"mitter\",\n", " dash_array=\"5, 10\",\n", " **kw,\n", ").add_to(m)\n", "\n", "\n", "folium.Rectangle(\n", " bounds=[[35.681, 139.766 - 2 * dx], [35.691, 139.7762 - 2 * dx]],\n", " line_join=\"bevel\",\n", " dash_array=\"15, 10, 5, 10, 15\",\n", " **kw,\n", ").add_to(m)\n", "\n", "m" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Polygon" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
Make this Notebook Trusted to load map: File -> Trust Notebook
" ], "text/plain": [ "" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "m = folium.Map(location=[35.67, 139.78], zoom_start=13)\n", "\n", "locations = [\n", " [35.6762, 139.7795],\n", " [35.6718, 139.7831],\n", " [35.6767, 139.7868],\n", " [35.6795, 139.7824],\n", " [35.6787, 139.7791],\n", "]\n", "\n", "folium.Polygon(\n", " locations=locations,\n", " color=\"blue\",\n", " weight=6,\n", " fill_color=\"red\",\n", " fill_opacity=0.5,\n", " fill=True,\n", " popup=\"Tokyo, Japan\",\n", " tooltip=\"Click me!\",\n", ").add_to(m)\n", "\n", "m" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
Make this Notebook Trusted to load map: File -> Trust Notebook
" ], "text/plain": [ "" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "locations = [\n", " [\n", " [7.577794326946673, 8.998503901433935],\n", " [7.577851434795945, 8.998572430673164],\n", " [7.577988491475764, 8.998652380403087],\n", " [7.578105560723088, 8.998426807051544],\n", " [7.577891409660878, 8.998289750371725],\n", " [7.577794326946673, 8.998503901433935],\n", " ],\n", " [\n", " [7.578139824893071, 8.999291979141560],\n", " [7.578359687549607, 8.999414759083890],\n", " [7.578456769364435, 8.999266281014116],\n", " [7.578471046101925, 8.999197181604700],\n", " [7.578247331649095, 8.999094883721964],\n", " [7.578139824893071, 8.99929197914156],\n", " ],\n", " [\n", " [7.577851730672876, 8.997811268775080],\n", " [7.578012579816743, 8.997460464828633],\n", " [7.577798113991832, 8.997311104523930],\n", " [7.577667902951418, 8.997663440915119],\n", " [7.577851730672876, 8.997811268775080],\n", " ],\n", " [\n", " [7.578562417221803, 8.999551816663029],\n", " [7.578688052511666, 8.999654609172921],\n", " [7.578813688700849, 8.999443313458185],\n", " [7.578670920426703, 8.999369073523950],\n", " [7.578562417221803, 8.999551816663029],\n", " ],\n", " [\n", " [7.577865711533433, 8.998252059784761],\n", " [7.577989601239152, 8.998002756022402],\n", " [7.577648754586391, 8.997784460884190],\n", " [7.577545911714481, 8.998069316645683],\n", " [7.577865711533433, 8.998252059784761],\n", " ],\n", "]\n", "\n", "m = folium.Map(location=[7.577798113991832, 8.997311104523930], zoom_start=16)\n", "\n", "folium.Polygon(\n", " locations=locations,\n", " smooth_factor=2,\n", " color=\"crimson\",\n", " no_clip=True,\n", " tooltip=\"Hi there!\",\n", ").add_to(m)\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.9.0" } }, "nbformat": 4, "nbformat_minor": 1 }