{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import folium" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "from xml.dom.minidom import parseString\n", "with open('WRSC2019_day3.kml', 'rt') as f:\n", " doc=f.read()\n", " p = parseString(doc)" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "nodes = p.getElementsByTagName('Placemark')\n", "way_points={}\n", "for n in nodes:\n", " raw_coord = n.getElementsByTagName('coordinates')[0].firstChild.nodeValue.split(',')\n", " name = (n.getElementsByTagName('name')[0].firstChild.nodeValue)\n", " way_points[name] = [float(raw_coord[1]), float(raw_coord[0])]" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "map_osm = folium.Map(location=way_points['marker1'], zoom_start=17)" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "def add_waypoint(name, latlon):\n", " folium.map.Marker(\n", " latlon,\n", " icon=folium.features.DivIcon(\n", " icon_size=(12,12),\n", " icon_anchor=(0,0),\n", " html='
{}
'.format(name),\n", " )\n", " ).add_to(map_osm)\n", " folium.CircleMarker(latlon, radius=5).add_to(map_osm)" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "marker_list = [['1', way_points['marker1']],\n", " ['2', way_points['marker2']],\n", " ['3', way_points['marker3']],\n", " ['4', way_points['marker4']]]" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [], "source": [ "def add_waypoint(name, latlon):\n", " folium.map.Marker(\n", " latlon,\n", " icon=folium.features.DivIcon(\n", " icon_size=(12,12),\n", " icon_anchor=(0,0),\n", " html='
{}
'.format(name),\n", " )\n", " ).add_to(map_osm)\n", " folium.CircleMarker(latlon, radius=5).add_to(map_osm)" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [], "source": [ "for marker in marker_list:\n", " add_waypoint(marker[0], marker[1])" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
" ], "text/plain": [ "" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "map_osm" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[['1', [29.86769032147261, 121.5385162033053]],\n", " ['2', [29.86719457094162, 121.5382643168712]],\n", " ['3', [29.86749690797608, 121.5391270316213]],\n", " ['4', [29.86702872486077, 121.5388580404463]]]" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "marker_list" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "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.6.3" } }, "nbformat": 4, "nbformat_minor": 2 }