{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import folium\n", "import pandas\n", "import yaml" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "from xml.dom.minidom import parseString\n", "with open('WRSC2019_day1.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['waypoint3'], 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 = [['A', way_points['waypoint1']],\n", " ['B', way_points['waypoint2']],\n", " ['C', way_points['waypoint3']],\n", " ['D', way_points['waypoint4']]]" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [], "source": [ "def calc_offset(wp, anchor):\n", " lat_offset = wp[0] - anchor[0]\n", " lon_offset = wp[1] - anchor[1]\n", " return [lat_offset, lon_offset]" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [], "source": [ "OFFSET = calc_offset(way_points['waypoint1'], way_points['anchor1'])" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [], "source": [ "def apply_offset(wp, OFFSET=OFFSET):\n", " return [wp[0] - OFFSET[0], wp[1] - OFFSET[1]]" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [], "source": [ "def add_waypoint_south(name, latlon):\n", " folium.map.Marker(\n", " apply_offset(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(apply_offset(latlon), radius=5).add_to(map_osm)" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [], "source": [ "for marker in marker_list:\n", " add_waypoint(marker[0], marker[1])\n", " add_waypoint_south(marker[0], marker[1]) # South" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
" ], "text/plain": [ "" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "map_osm" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[['A', [29.86713941703848, 121.5389755240182]],\n", " ['B', [29.86705406261338, 121.5385997804418]],\n", " ['C', [29.86720864100981, 121.5386780355552]],\n", " ['D', [29.86729537733915, 121.5384019484949]]]" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "marker_list # South" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[29.86747564425439, 121.5391664546322]\n", "[29.86739028982929, 121.5387907110558]\n", "[29.86754486822572, 121.53886896616919]\n", "[29.86763160455506, 121.53859287910889]\n" ] } ], "source": [ "for marker in marker_list:\n", " print(apply_offset(marker[1])) # North" ] }, { "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 }