{ "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_day4.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": 6, "metadata": {}, "outputs": [], "source": [ "marker_list = [['A', way_points['marker1']],\n", " ['B', way_points['marker2']]]" ] }, { "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": 9, "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": 10, "metadata": {}, "outputs": [], "source": [ "OFFSET = calc_offset(way_points['marker1'], way_points['anchor1'])" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [], "source": [ "def apply_offset(wp, OFFSET=OFFSET):\n", " return [wp[0] - OFFSET[0], wp[1] - OFFSET[1]]" ] }, { "cell_type": "code", "execution_count": 12, "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": 13, "metadata": {}, "outputs": [], "source": [ "for marker in marker_list:\n", " add_waypoint(marker[0], marker[1])\n", " add_waypoint_south(marker[1], marker[1]) # South" ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
" ], "text/plain": [ "" ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "map_osm" ] }, { "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 }