{ "cells": [ { "cell_type": "markdown", "id": "11ce8688-2dd2-4a18-aa6c-bce96a801782", "metadata": { "nbgrader": { "grade": false, "grade_id": "cell-1720c646ec279d2e", "locked": true, "schema_version": 3, "solution": false, "task": false } }, "source": [ "# 8. Programmierübung: Folium\n", "\n", "
\n", "
\n", " Willkommen zur achten Programmierübung Einführung in Python 3.\n", "
\n", " \n", "
\n", "\n", "Wenn Sie Fragen oder Verbesserungsvorschläge zum Inhalt oder Struktur der Notebooks haben, dann können sie eine E-Mail an Phil Keier ([p.keier@hbk-bs.de](mailto:p.keier@hbk-bs.de?subject=[SigSys]%20Feedback%20Programmierübung&)) oder Martin Le ([martin.le@tu-bs.de](mailto:martin.le@tu-bs.de?subject=[SigSys]%20Feedback%20Programmierübung&)) schreiben.\n", "\n", "Link zu einem Python Spickzettel: [hier](https://s3.amazonaws.com/assets.datacamp.com/blog_assets/PythonForDataScience.pdf)\n", "\n", "Der Großteil des Python-Tutorials stammt aus der Veranstaltung _Deep Learning Lab_ und von [www.python-kurs.eu](https://www.python-kurs.eu/python3_kurs.php) und wurde für _Signale und Systeme_, sowie _Einführung in die Programmierung für Nicht Informatiker_ angepasst.\n", "\n", "---" ] }, { "cell_type": "markdown", "id": "ebd295cc-8e6d-435e-a91a-881bf3798b5b", "metadata": { "nbgrader": { "grade": false, "grade_id": "cell-275178a1d9bade57", "locked": true, "schema_version": 3, "solution": false, "task": false }, "tags": [] }, "source": [ "# Geospatial Data\n", "\n", "In the following we will look at how maps can be displayed using Python & the Folium API.\n", "\n", "[Folium](https://python-visualization.github.io/folium/) is a Python wrapper that binds the open source library [Leaflet.js](https://leafletjs.com/).\n", "\n", "In this way, the developers aim to combine the advantages of data processing with Python, as well as the visualization advantages of the Web.\n", "\n", "Objectives of this exercise:\n", "1. create simple maps with different terrain options\n", "2. set and adjust markers\n", " 1. creating a marker\n", " 2. popup & tooltip\n", " 3. icons & colors\n", " 4. circle marker\n", " 5. setting own markers\n", "3. layer groups\n", "4. plugins\n", "5. handling GeoJSON data\n", "\n", "\n", "__For the entire exercise, all parameters are basically given for illustrative purposes. Unless explicitly requested, you do not have to do this.__" ] }, { "cell_type": "markdown", "id": "22adfbb3-e71d-4228-ac02-b8c7135a8943", "metadata": { "nbgrader": { "grade": false, "grade_id": "cell-d928ae513b1e6ce0", "locked": true, "schema_version": 3, "solution": false, "task": false } }, "source": [ "# Import Folium\n", "\n", "First we need to Import Folium as follows:" ] }, { "cell_type": "code", "execution_count": 1, "id": "2725fd60-dbe5-4739-8cbf-3ef9a585032f", "metadata": { "nbgrader": { "grade": false, "grade_id": "cell-a22fce114edbd7bf", "locked": true, "schema_version": 3, "solution": false, "task": false } }, "outputs": [], "source": [ "# Execute this cell everytime you restart the notebook!!!\n", "import folium" ] }, { "cell_type": "markdown", "id": "4a676854-ebc9-439f-8414-5fe39e65dc13", "metadata": { "nbgrader": { "grade": false, "grade_id": "cell-d18e7620cb44ddf4", "locked": true, "schema_version": 3, "solution": false, "task": false }, "tags": [] }, "source": [ "## Creating maps\n", "\n", "The default object of every Folium App is the [Map](https://python-visualization.github.io/folium/modules.html#module-folium.map).\n", "\n", "### Location\n", "To create it, you only need the _location_ parameter which takes a tuple (or list) of two floats.\n", "The first value is the latitude (lat) and the second the longitude (lon). (For Braunschweig this would be lat: 52.264150 & lon: 10.526420)\n", "\n", "### Tiles\n", "Folium supports the display of different types of maps. These are specified as a string for the tiles parameter when creating the map.\n", "\n", "Possible maps are:\n", "\n", "1. _OpenStreetMap_ (default)\n", "2. _Stamen Terrain_\n", "3. _Stamen Toner_\n", "\n", "### Zoom\n", "The default _zoom_ setting of the map can be adjusted by the following 3 parameters:\n", "\n", "- _zoom_start_ (default: 10) creates the map with a zoom setting between _min_zoom_ & _max_zoom_.\n", "- _min_zoom_ (default: 0) & _max_zoom_ (default: 18) limits the possible zoom radius. Generally not necessary.\n", "\n", "### Optimization\n", "If one of the following cells has excessive computation times, the parameter _prefer_canvas=True_ should be specified for the map object. This will force the web browser to use the web graphics library ([WebGL](https://github.com/KhronosGroup/WebGL)) and will result in a speed bonus, e.g. thousands of markers. By default _prefer_canvas_ is set to _False_ and should only be used if you really want to display lots of data!\n", "\n", "The following example illustrates the creation of the map object:" ] }, { "cell_type": "code", "execution_count": 2, "id": "ecd035c9-c1bc-4393-8681-2c058caca527", "metadata": { "nbgrader": { "grade": false, "grade_id": "cell-1a3da7284c8a4450", "locked": true, "schema_version": 3, "solution": false, "task": false }, "tags": [] }, "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": [ "m = folium.Map(\n", " location=(52.264150, 10.526420),\n", " tiles='OpenStreetMap',\n", " #iles='Stamen Toner',\n", " zoom_start=13,\n", " prefer_canvas=False\n", " )\n", "\n", "m" ] }, { "cell_type": "markdown", "id": "94976e7f-1354-428e-ba9d-32ad696e27f4", "metadata": { "nbgrader": { "grade": false, "grade_id": "cell-bbb8367d84f43da2", "locked": true, "schema_version": 3, "solution": false, "task": false }, "tags": [] }, "source": [ "## Exercise 1: Create a map\n", "\n", "Create a map with the coordinates of your hometown, or your favorite city (Braunschweig does not count as a solution). Save your Solution in the variable `my_map`.\n", "\n", "Adjust the _zoom_start_ parameter so that your place is visible in the center. To find out which coordinates your place has you can use the online tool [latlong.net](https://www.latlong.net/).\n", "\n", "Use _CartoDB Positron_ as tileset.\n", "\n", "Set the _prefer_canvas_ parameter to _True_.\n", "\n", "Also please add your city as a comment.\n", "\n", "In case of problems, please check the Folium API [Map](https://python-visualization.github.io/folium/modules.html#module-folium.map) object.\n" ] }, { "cell_type": "code", "execution_count": 3, "id": "a05ad147-1990-4d96-983d-c128b60125b5", "metadata": { "nbgrader": { "grade": true, "grade_id": "cell-6099ccde55688a94", "locked": false, "points": 4, "schema_version": 3, "solution": true, "task": false }, "tags": [] }, "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": [ "# Your City: \n", "### BEGIN SOLUTION\n", "# Your City: Braunschweig\n", "my_map = folium.Map(\n", " location=(52.264150, 10.526420),\n", " tiles='cartodb positron',\n", " zoom_start=13,\n", " prefer_canvas=True\n", " )\n", "my_map\n", "### END SOLUTION" ] }, { "cell_type": "code", "execution_count": 4, "id": "b554a2ec-d32e-4ea6-a91f-a1fe554804cd", "metadata": { "nbgrader": { "grade": true, "grade_id": "cell-1b94f6587760b8e8", "locked": true, "points": 3, "schema_version": 3, "solution": false, "task": false } }, "outputs": [], "source": [ "# Your Solutions are tested here...\n", "assert isinstance(my_map, folium.Map)\n", "assert isinstance(my_map.location, list)\n", "assert len(my_map.location) == 2" ] }, { "cell_type": "markdown", "id": "d057d2a5-9699-4a88-bea7-46adaa096f54", "metadata": { "nbgrader": { "grade": false, "grade_id": "cell-ad368f2ba205c714", "locked": true, "schema_version": 3, "solution": false, "task": false }, "tags": [] }, "source": [ "## Marker \n", "\n", "The quintessence of any GeoSpatial Data project is the visualization of data.\n", "\n", "The [Marker](https://python-visualization.github.io/folium/modules.html#folium.map.Marker) object expects the following parameters:\n", "- _location_ (Mandatory) Tuple of Floats (Like Map Object) to set a marker.\n", "- _popup_ (String or folium.Popup object) small info box that can be customized using HTML\n", "- _tooltip_ (String) hover text with instruction\n", "- _icon_ (folium.Icon) to customize the marker\n", "- _dragable_ (bool, default False) allows the user to move the marker\n", "\n", "To set a simple marker it is first created with a location.\n", "Then the marker has to be added to the map with the function _add_to()_. \n", "\n", "In the following the HBK BS should be marked on the map." ] }, { "cell_type": "code", "execution_count": 29, "id": "59a91300-1dc7-4d27-826c-14a94fa13a45", "metadata": { "nbgrader": { "grade": false, "grade_id": "cell-3b289b02455e2512", "locked": true, "schema_version": 3, "solution": false, "task": false }, "tags": [] }, "outputs": [ { "data": { "text/html": [ "
Make this Notebook Trusted to load map: File -> Trust Notebook
" ], "text/plain": [ "" ] }, "execution_count": 29, "metadata": {}, "output_type": "execute_result" } ], "source": [ "m = folium.Map(\n", " location=(52.264150, 10.526420),\n", " tiles='OpenStreetMap',\n", " zoom_start=14,\n", " prefer_canvas=False\n", " )\n", "\n", "my_marker = folium.Marker(\n", " location=(52.25802230834961, 10.503097534179688)\n", " )\n", "\n", "my_marker.add_to(m)\n", "\n", "m" ] }, { "cell_type": "markdown", "id": "179b1901-ac37-4724-aa59-c76345c61805", "metadata": { "nbgrader": { "grade": false, "grade_id": "cell-d9ba7c4b83368403", "locked": true, "schema_version": 3, "solution": false, "task": false }, "tags": [] }, "source": [ "After executing the code you should see a marker at the address Johannes-Selenka-Platz 1, 38118 Braunschweig.\n", "\n", "Since this is relatively boring we will now try to adapt the marker to our needs." ] }, { "cell_type": "markdown", "id": "071b4725-8f13-4d38-9ea6-8f62826baf17", "metadata": { "nbgrader": { "grade": false, "grade_id": "cell-0fd8e8915f7f9613", "locked": true, "schema_version": 3, "solution": false, "task": false }, "tags": [] }, "source": [ "### Popup & Tooltip\n", "\n", "The marker accepts strings as _tooltip_ & _popup_ parameters, as the following example demonstrates.\n", "This is the most primitive form of how a simple marker can be created with information.\n", "\n", "To understand what the _tooltip_ parameter does, run the next example and hover over the marker. Clicking on the marker will display the contents of the _popup_ parameter." ] }, { "cell_type": "code", "execution_count": 30, "id": "33a5ffa1-7f39-46d4-9a17-35b3c8eb26ef", "metadata": { "nbgrader": { "grade": false, "grade_id": "cell-8b6f8ca79a9a05c3", "locked": true, "schema_version": 3, "solution": false, "task": false }, "tags": [] }, "outputs": [ { "data": { "text/html": [ "
Make this Notebook Trusted to load map: File -> Trust Notebook
" ], "text/plain": [ "" ] }, "execution_count": 30, "metadata": {}, "output_type": "execute_result" } ], "source": [ "m = folium.Map(\n", " location=(52.264150, 10.526420),\n", " tiles='OpenStreetMap',\n", " zoom_start=16,\n", " prefer_canvas=False\n", " )\n", "\n", "# Schloss Braunschweig\n", "castle_popup = \"Ritterbrunnen 1, 38100 Braunschweig\"\n", "castle_tooltip = \"More about the castle\"\n", "\n", "\n", "castle_marker = folium.Marker(\n", " location=(52.2643, 10.529),\n", " popup=castle_popup,\n", " tooltip=castle_tooltip\n", " )\n", "castle_marker.add_to(m)\n", "\n", "m" ] }, { "cell_type": "markdown", "id": "cadd0223-d6d5-445a-ac7b-ead3b010260f", "metadata": { "nbgrader": { "grade": false, "grade_id": "cell-cfc72d893f2572ff", "locked": true, "schema_version": 3, "solution": false, "task": false }, "tags": [] }, "source": [ "### HTML Popups\n", "\n", "To do justice to the inner artist as well, markers can also be designed in Folium using the tools of the modern internet.\n", "\n", "The Folium object [Popup](https://python-visualization.github.io/folium/modules.html#folium.map.Popup) can be used to display simple HTML strings. \n", "\n", "Before we get to the main features of HTML for Folium, we will first take a look at the other optional parameters of the Popup object.\n", "\n", "These include:\n", "\n", "- _parse_html_ (bool, default False) not normally needed, forces Folium to interpret the HTML string first. Useful for any customization via JavaScript.\n", "- _max_width_ (int or str, default '100%') sets the maximum width of the popup. For the str parameter it is important to include the '%' character.\n", "- _show_ (bool, default False) if this parameter is set to _True_, the popup will load when the map is opened.\n", "- _sticky_ (bool, default False) if this parameter is set to _True_, the popup will not be closed.\n", "\n", "\n", "Mandatory for creating a popup is the _html_ parameter. This parameter requires a (multi-)string containing HTML code.\n", "\n", "As an example we will create a HBK BS popup which renders the following HTML:\n", "\n", "---\n", "

\n", "\"HBK\n", "

\n", "

Johannes-Selenka-Platz 1

\n", "

38118 Braunschweig

\n", "

Germany, DE

\n", "

Visit: hbk-bs.de

\n", "\n", "---\n", "\n", "\n", "and the associated HTML:\n", "\n", "\n", "```html\n", "

\n", "\"HBK\n", "

\n", "

Johannes-Selenka-Platz 1

\n", "

38118 Braunschweig

\n", "

Germany, DE

\n", "

Visit: hbk-bs.de

\n", "```\n", "\n", "\n", "Do not let this confuse you. The statements in between `<> & ` are HTML tags, for example `

` represents a 'Paragraph' & `` represents a hyperlink. \n", "For the text semantic elements I recommend the following [reference](https://www.w3.org/html/wiki/Elements).\n", "\n", "In Python, no HTML can be displayed directly. For this, the entire HTML must be within a string. To simplify the readability Python offers the multiline string notated with 3 `'''`:\n", "\n", "\n", "\n", "'''\n", "hi I am\n", "\n", "\n", "a\n", "\n", "multiline string\n", "'''\n", "\n", "\n", "And as with the already known string, this one supports all string format options. But more about that later in the Factory Patterns part.\n" ] }, { "cell_type": "code", "execution_count": 7, "id": "db9725a6-c438-4a23-9e5b-5b401d412832", "metadata": { "nbgrader": { "grade": false, "grade_id": "cell-b683105305025808", "locked": true, "schema_version": 3, "solution": false, "task": false }, "tags": [] }, "outputs": [], "source": [ "# HBK Braunschweig\n", "hbk_popup_html = folium.Popup(\n", " '''\n", "

\n", " \"HBK\n", "

\n", "

Johannes-Selenka-Platz 1

\n", "

38118 Braunschweig

\n", "

Germany, DE

\n", "

Visit: hbk-bs.de

\n", " ''',\n", " show=True\n", " )\n", "\n", "hbk_tooltip = \"More about the university\"" ] }, { "cell_type": "markdown", "id": "2773d557-e6ca-406c-9de1-b9c0675e0604", "metadata": { "nbgrader": { "grade": false, "grade_id": "cell-cf6a889f7ebf8a54", "locked": true, "schema_version": 3, "solution": false, "task": false }, "tags": [] }, "source": [ "### Icon\n", "\n", "The last step to complete the marker is the [Icon](https://python-visualization.github.io/folium/modules.html#folium.map.Icon) object.\n", "\n", "Unlike the other objects discussed, this one has no mandatory parameters.\n", "\n", "As usual, here is an explanation of the parameters:\n", "- _color_ (str, default 'blue') sets the color of the marker.\n", "\n", " Possible colors are: \n", " - red, blue, green,\n", " - purple, orange, darkred,\n", " - lightred, beige, darkblue,\n", " - darkgreen, cadetblue, darkpurple,-\n", " - white, pink, lightblue,\n", " - lightgreen, gray, black,\n", " - lightgray\n", " \n", " \n", " or any hexadecimal value noted with '#XXXXXX'.\n", "\n", "- _icon_color_ (str, default 'white') sets the color of the glyphicon. The possible color values are the same as for _color_.\n", "- _angle_ (int, default 0) sets the rotation of the glyphicon. The possible values are limited to the range 0-359 integer.\n", "- _prefix_ (str, default 'glyphicon) can take two values 'fa' for the icons of the website [Font Awesome](https://fontawesome.com/icons) (Attention not all icons are free) and 'glyphicon' for the icons of the website [Bootstrap](https://getbootstrap.com/docs/3.3/components/) (All icons behind this link are free). The value in _prefix_ specifies which website is queried. \n", "- _icon_ (str, default 'info-sign') specifies the name of the icon to be displayed and is therefore dependent on the _prefix_ parameter. The default icon is 'glyphicon glyphicon-info-sign'.\n", "\n", "To design a reasonable icon for the HBK marker the following example should be understood:" ] }, { "cell_type": "code", "execution_count": 8, "id": "8f79bd13-82f0-478c-8409-1e97d79d4b26", "metadata": { "nbgrader": { "grade": false, "grade_id": "cell-5e1cf782bc0512c1", "locked": true, "schema_version": 3, "solution": false, "task": false }, "tags": [] }, "outputs": [], "source": [ "hbk_icon = folium.Icon(\n", " color='black',\n", " icon_color='#deddda',\n", " prefix='glyphicon',\n", " icon='glyphicon-home',\n", " angle=0\n", " )" ] }, { "cell_type": "markdown", "id": "4a2ffb76-8045-4cba-a416-5555f521889b", "metadata": { "nbgrader": { "grade": false, "grade_id": "cell-8d4b5a5cb9cc90cc", "locked": true, "schema_version": 3, "solution": false, "task": false }, "tags": [] }, "source": [ "After successfully creating the three variables _hbk_tooltip_, _hbk_html_popup_ & _hbk_icon_, we now display the customized marker:" ] }, { "cell_type": "code", "execution_count": 9, "id": "852785cc-0dff-4c2c-b6bb-20d08e26349f", "metadata": { "nbgrader": { "grade": false, "grade_id": "cell-62068ff221befbb2", "locked": true, "schema_version": 3, "solution": false, "task": false }, "tags": [] }, "outputs": [ { "data": { "text/html": [ "
Make this Notebook Trusted to load map: File -> Trust Notebook
" ], "text/plain": [ "" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "m = folium.Map(\n", " location=(52.258, 10.5),\n", " tiles='OpenStreetMap',\n", " zoom_start=16,\n", " prefer_canvas=False\n", " )\n", "\n", "hbk_marker = folium.Marker(\n", " location=(52.257770, 10.502490),\n", " popup=hbk_popup_html,\n", " tooltip=hbk_tooltip,\n", " icon=hbk_icon\n", " )\n", "\n", "hbk_marker.add_to(m)\n", "\n", "m" ] }, { "cell_type": "markdown", "id": "6a7a1f4d-720b-4152-a90b-c9a194494cbe", "metadata": { "nbgrader": { "grade": false, "grade_id": "cell-a6152b205ccf50ed", "locked": true, "schema_version": 3, "solution": false, "task": false }, "tags": [] }, "source": [ "## Exercise 2: Design your own Marker\n", "\n", "In the following exercise you will design your own marker.\n", "\n", "In case of problems, please check the Folium API:\n", "- [Marker](https://python-visualization.github.io/folium/modules.html#folium.map.Marker)\n", "- [Popup](https://python-visualization.github.io/folium/modules.html#folium.map.Popup)\n", "- [Icon](https://python-visualization.github.io/folium/modules.html#folium.map.Icon)\n", "- [Tooltip](https://python-visualization.github.io/folium/modules.html#folium.map.Tooltip)" ] }, { "cell_type": "markdown", "id": "093f0526-114f-45da-947a-550f2163030a", "metadata": { "nbgrader": { "grade": false, "grade_id": "cell-d5aa18ce07303756", "locked": true, "schema_version": 3, "solution": false, "task": false }, "tags": [] }, "source": [ "### 2.1: Defining a Tooltip\n", "\n", "Define a tooltip variable named `tooltip` with the text `More about TU Braunschweig`." ] }, { "cell_type": "code", "execution_count": 10, "id": "725abb1e-f8c4-4cca-be6f-326f23126062", "metadata": { "nbgrader": { "grade": false, "grade_id": "cell-04f53b3f7eb6c201", "locked": false, "schema_version": 3, "solution": true, "task": false }, "tags": [] }, "outputs": [], "source": [ "### BEGIN SOLUTION\n", "tooltip = \"More about TU Braunschweig\"\n", "### END SOLUTION" ] }, { "cell_type": "code", "execution_count": 11, "id": "d0c93b34-79de-4a90-b595-dec419b3a930", "metadata": { "nbgrader": { "grade": true, "grade_id": "cell-bfcb53d3e2aba304", "locked": true, "points": 1, "schema_version": 3, "solution": false, "task": false } }, "outputs": [], "source": [ "# Your Solutions are tested here...\n", "assert tooltip == \"More about TU Braunschweig\"" ] }, { "cell_type": "markdown", "id": "97aa8013-defd-408d-8b80-2389ff92904c", "metadata": { "nbgrader": { "grade": false, "grade_id": "cell-e943331e564dd5c6", "locked": true, "schema_version": 3, "solution": false, "task": false }, "tags": [] }, "source": [ "### 2.2: Defining a Popup\n", "\n", "Define a popup object with HTML text named `tu_popup_html` and the [TU BS Logo](https://www.google.com/url?sa=i&url=https%3A%2F%2Fde.m.wikipedia.org%2Fwiki%2FDatei%3ASiegel_TU_Braunschweig_transparent.svg&psig=AOvVaw3PFFLWsIPyXrT81Jo4F6ot&ust=1669222516763000&source=images&cd=vfe&ved=0CA8QjRxqFwoTCIjR-MqgwvsCFQAAAAAdAAAAABAE).\n", "\n", "Address: _Universitätspl. 2, 38106 Braunschweig_\n", "\n", "Logo URL: https://upload.wikimedia.org/wikipedia/commons/thumb/9/9d/Siegel_TU_Braunschweig_transparent.svg/1200px-Siegel_TU_Braunschweig_transparent.svg.png\n", "\n", "You can also use the Template from the Explanation.\n", "\n", "You can find a HTML reference [here](https://www.w3.org/html/wiki/Elements). If you write better in Markdown I recommend the following [converter](https://markdowntohtml.com/) and this [Markdown reference](https://www.markdownguide.org/cheat-sheet/)." ] }, { "cell_type": "code", "execution_count": 12, "id": "599b4313-9d53-46d8-be0e-dbf0ab707105", "metadata": { "nbgrader": { "grade": true, "grade_id": "cell-1f5f10be1f0c3e95", "locked": false, "points": 1, "schema_version": 3, "solution": true, "task": false }, "tags": [] }, "outputs": [], "source": [ "### BEGIN SOLUTION\n", "tu_popup_html = folium.Popup(\n", " '''\n", "

\n", " \"TU\n", "

\n", "

Universitätspl. 2

\n", "

38106 Braunschweigg

\n", "

Germany, DE

\n", "

Visit: tu-bs.de

\n", " ''',\n", " show=False\n", " )\n", "### END SOLUTION" ] }, { "cell_type": "markdown", "id": "541653fa-f882-4f15-90bb-2ad7665d380f", "metadata": { "nbgrader": { "grade": false, "grade_id": "cell-d0ad985cc098c85f", "locked": true, "schema_version": 3, "solution": false, "task": false } }, "source": [ "### 2.3 Defining an Icon\n", "\n", "Next, a _red_ icon named `tu_icon` should be defined.\n", "\n", "The color for the glyphicon should be a gray hexcode that you can choose freely. To make the color selection easier you can use the [Color Picker](https://htmlcolorcodes.com/color-picker/).\n", "\n", "As glyph, _glyphicon-education_, should be used." ] }, { "cell_type": "code", "execution_count": 13, "id": "7adb36ce-9012-4a9a-b025-2b7a91b4d2ac", "metadata": { "nbgrader": { "grade": true, "grade_id": "cell-3ec775c00a9d80a2", "locked": false, "points": 4, "schema_version": 3, "solution": true, "task": false }, "tags": [] }, "outputs": [], "source": [ "tu_icon = None\n", "### BEGIN SOLUTION\n", "tu_icon = folium.Icon(\n", " color='red',\n", " icon_color='#eeeeee',\n", " prefix='glyphicon',\n", " icon='glyphicon-education',\n", " angle=0\n", " )\n", "### END SOLUTION" ] }, { "cell_type": "markdown", "id": "287924de-5810-4f3c-8b36-e3308798b3ea", "metadata": { "nbgrader": { "grade": false, "grade_id": "cell-b16e407b56f6a000", "locked": true, "schema_version": 3, "solution": false, "task": false }, "tags": [] }, "source": [ "### 2.4 Defining a Marker\n", "\n", "All previously created objects should now be combined into one marker named `tu_bs_marker`.\n", "\n", "As the location data use `(52.273460, 10.529231)`." ] }, { "cell_type": "code", "execution_count": 14, "id": "c7dd4f94-e7d2-4c11-9426-f911462e122c", "metadata": { "nbgrader": { "grade": true, "grade_id": "cell-43ce13ffa68645bc", "locked": false, "points": 4, "schema_version": 3, "solution": true, "task": false }, "tags": [] }, "outputs": [], "source": [ "tu_bs_marker = None\n", "### BEGIN SOLUTION\n", "tu_bs_marker = folium.Marker(\n", " location=(52.273460, 10.529231),\n", " popup=tu_popup_html,\n", " tooltip=tooltip,\n", " icon=tu_icon\n", " )\n", "### END SOLUTION" ] }, { "cell_type": "code", "execution_count": 15, "id": "13fa1a0f-f06e-4042-bae6-254fc99640e7", "metadata": { "nbgrader": { "grade": false, "grade_id": "cell-365a8eef0b32decd", "locked": true, "schema_version": 3, "solution": false, "task": false }, "tags": [] }, "outputs": [ { "data": { "text/html": [ "
Make this Notebook Trusted to load map: File -> Trust Notebook
" ], "text/plain": [ "" ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Your Solutions are tested and displayed here...\n", "m = folium.Map(\n", " location=(52.274, 10.53),\n", " tiles='OpenStreetMap',\n", " zoom_start=17,\n", " prefer_canvas=False\n", " )\n", "\n", "tu_bs_marker.add_to(m)\n", "m" ] }, { "cell_type": "markdown", "id": "6639280d-2c23-421b-9170-418895482fb3", "metadata": { "nbgrader": { "grade": false, "grade_id": "cell-8cf61a16719f867b", "locked": true, "schema_version": 3, "solution": false, "task": false }, "tags": [] }, "source": [ "### Circle & Circle Marker\n", "\n", "Another possibility to mark places on maps is the [Circle](https://python-visualization.github.io/folium/modules.html#folium.vector_layers.Circle) and the [CircleMarker](https://python-visualization.github.io/folium/modules.html#folium.vector_layers.CircleMarker). The only difference between the two is the parameter _radius_ which is not fixed for the circle and has a default value of 10 for the circle marker which is specified in pixels, the circle marker scales with the map when zooming. Otherwise the objects _popup_ & _tooltip_ can be set with the marker. For the coloring the parameters _color_ & _fill_color_ are to be assigned. _color_ describes the color of the outer ring of the circle, while _fill_color_ specifies the fill color of the circle, whose default value is copied from the parameter_color_. to use _fill_color_ the parameter _fill_ must also be set to _True_.\n", "\n", "Here is an example.\n", "\n", "The HBK is marked with a red filled circle marker, which has the radius 100 pixel. To highlight the area inside the HBK, black is used as fill color.\n", "Also here a tooltip, as well as the usual HBK popup is specified." ] }, { "cell_type": "code", "execution_count": 16, "id": "511b9c23-f335-4639-8120-289ee9d4fee2", "metadata": { "nbgrader": { "grade": false, "grade_id": "cell-06a4d0cb95f20d93", "locked": true, "schema_version": 3, "solution": false, "task": false }, "tags": [] }, "outputs": [ { "data": { "text/html": [ "
Make this Notebook Trusted to load map: File -> Trust Notebook
" ], "text/plain": [ "" ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Map Setup\n", "m = folium.Map(\n", " location=(52.258, 10.5),\n", " tiles='OpenStreetMap',\n", " zoom_start=16,\n", " prefer_canvas=False\n", " )\n", "\n", "# HBK Braunschweig\n", "hbk_popup_html = folium.Popup(\n", " '''\n", "

\n", " \"HBK\n", "

\n", "

Johannes-Selenka-Platz 1

\n", "

38118 Braunschweig

\n", "

Germany, DE

\n", "

Visit: hbk-bs.de

\n", " ''',\n", " show=False\n", " )\n", "\n", "# Defining tooltip\n", "hbk_tooltip = \"More about the university\"\n", "\n", "# Create Circle Marker\n", "hbk_circle_marker = folium.Circle(\n", " location=(52.2572, 10.501),\n", " popup=hbk_popup_html,\n", " tooltip=hbk_tooltip,\n", " radius=100,\n", " fill=True,\n", " fill_color='black',\n", " color='red'\n", " )\n", "\n", "# Attach Circle Marker to map\n", "hbk_circle_marker.add_to(m)\n", "\n", "m" ] }, { "cell_type": "markdown", "id": "c8bcbdc6-3b3a-4421-b78f-8c62f7f03d34", "metadata": { "nbgrader": { "grade": false, "grade_id": "cell-90296cc00bae2968", "locked": true, "schema_version": 3, "solution": false, "task": false } }, "source": [ "### Rectangle \n", "\n", "Rectangles can also be defined in the same way. Instead of a location with a radius, the two corner points must be specified. The data structure used for this is a list of tuples (_[tuple, tuple]_).\n", "\n", "Consider the following example:" ] }, { "cell_type": "code", "execution_count": 17, "id": "eee0d9ff-1ada-4f62-9675-39064b68fa32", "metadata": { "nbgrader": { "grade": false, "grade_id": "cell-641478b6b1df4ae5", "locked": true, "schema_version": 3, "solution": false, "task": false }, "tags": [] }, "outputs": [ { "data": { "text/html": [ "
Make this Notebook Trusted to load map: File -> Trust Notebook
" ], "text/plain": [ "" ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Map Setup\n", "m = folium.Map(\n", " location=(52.258, 10.5),\n", " tiles='OpenStreetMap',\n", " zoom_start=16,\n", " prefer_canvas=False\n", " )\n", "\n", "# HBK Braunschweig\n", "hbk_popup_html = folium.Popup(\n", " '''\n", "

\n", " \"HBK\n", "

\n", "

Johannes-Selenka-Platz 1

\n", "

38118 Braunschweig

\n", "

Germany, DE

\n", "

Visit: hbk-bs.de

\n", " ''',\n", " show=False\n", " )\n", "\n", "# Defining tooltip\n", "hbk_tooltip = \"More about the university\"\n", "\n", "# Create Rectangle Marker\n", "hbk_rectangle_marker = folium.Rectangle(\n", " bounds=[(52.258077, 10.498424), (52.255896, 10.504092)], # List of tuples defining the Corner Points\n", " popup=hbk_popup_html,\n", " tooltip=hbk_tooltip,\n", " fill=True,\n", " fill_color='black',\n", " color='red'\n", " )\n", "\n", "# Attach Rectangle Marker to map\n", "hbk_rectangle_marker.add_to(m)\n", "\n", "m" ] }, { "cell_type": "markdown", "id": "09574eea-8007-4740-b3f5-e81a40c28cbd", "metadata": { "nbgrader": { "grade": false, "grade_id": "cell-5d436ff9290eb683", "locked": true, "schema_version": 3, "solution": false, "task": false } }, "source": [ "## Builder Pattern\n", "\n", "To simplify working with Folium, certain techniques can be used to simplify the creation of objects. \n", "\n", "Design patterns are known from the technical literature that lead to a simpler, error-free and clearer way of developing software. \n", "One of these design patterns, the creation pattern, will be presented below and used for future tasks.\n", "\n", "The technical literature states freely quoted:\n", "\"The creation pattern serves to decouple the construction of objects from their representation!\" - [_Design Patterns: Elements of Reusable Object-Oriented Software\n", "by Erich Gamma, Ralph Johnson, Richard Helm, Ralph E. Johnson, John Vlissides_](https://books.google.de/books?hl=de&lr=&id=tmNNfSkfTlcC&oi=fnd&pg=PR11&dq=software+design+patterns&ots=e_iImZT2d3&sig=DtkhOov5t0Ot6lf7QubDGNhWzz0#v=onepage&q=software%20design%20patterns&f=false)\n", "\n", "A builder is a function (function of an object) that is used to create new objects. In our case, these will be markers and popups." ] }, { "cell_type": "markdown", "id": "5f27eaae-3e5b-4f6c-854a-2c37c9fbffac", "metadata": { "nbgrader": { "grade": false, "grade_id": "cell-6473594d5d9882b0", "locked": true, "schema_version": 3, "solution": false, "task": false } }, "source": [ "### A simple Popup Factory\n", "\n", "Anyone who remembers the HTML popups in the previous chapter will quickly realise that with a larger data set, setting individual HTML tags for images, addresses or other information soon becomes a tedious task.\n", "\n", "Assuming we want to plot all the universities in Lower Saxony on a map, a separate popup would have to be created for each marker. To change this, the following function will be introduced:" ] }, { "cell_type": "code", "execution_count": 18, "id": "ec9a37e4-1dd3-4673-b36f-122adafadeb2", "metadata": { "nbgrader": { "grade": false, "grade_id": "cell-069cd8284c5bc36c", "locked": true, "schema_version": 3, "solution": false, "task": false } }, "outputs": [], "source": [ "def popup_factory(adr: str, zipc: str, country: str, pic: str):\n", " html = '''\n", "

\n", "

{}

\n", "

{}

\n", "

{}

\n", " '''.format(pic, adr, zipc, country)\n", " return folium.Popup(html)" ] }, { "cell_type": "markdown", "id": "1740ce5e-f7a8-47f9-8211-7a62b19cf08b", "metadata": { "nbgrader": { "grade": false, "grade_id": "cell-de4c7e1824c4e5a6", "locked": true, "schema_version": 3, "solution": false, "task": false } }, "source": [ "The _popup_factory_ function just defined takes the four string parameters _adr_ (address), _zipc_ (postcode), _country_ & _pic_ (picture URL) and generates an HTML-compliant string with the given information from the string specified in the _html_ variable. The return value of the function is a Folium popup object.\n", "\n", "To get closer to the goal of plotting all universities in Lower Saxony, a few objects are still missing.\n", "\n", "The _hbk_icon_ I created above is to be used as the standard icon. It is defined as follows:" ] }, { "cell_type": "code", "execution_count": 19, "id": "9dddf885-ffa7-4e3b-b948-43ded7f3bd7b", "metadata": { "nbgrader": { "grade": false, "grade_id": "cell-a700169d2ec58d8c", "locked": true, "schema_version": 3, "solution": false, "task": false } }, "outputs": [], "source": [ "def icon_factory(is_public=True):\n", " icon = folium.Icon(\n", " color='black' if is_public else 'white',\n", " icon_color = 'white' if is_public else 'black',\n", " icon='glyphicon-home'\n", " )\n", " return icon" ] }, { "cell_type": "markdown", "id": "d4f4be32-8d71-41b0-9d8e-5ec2e32416a8", "metadata": { "nbgrader": { "grade": false, "grade_id": "cell-3fd735bc0f0cba70", "locked": true, "schema_version": 3, "solution": false, "task": false } }, "source": [ "The only thing missing in the next step is the factory for creating markers.\n", "\n", "This is defined as follows:" ] }, { "cell_type": "code", "execution_count": 20, "id": "07a0df3e-92f9-4e25-89f3-3e27048d2c6b", "metadata": { "nbgrader": { "grade": false, "grade_id": "cell-393cf1e2b37be7a6", "locked": true, "schema_version": 3, "solution": false, "task": false } }, "outputs": [], "source": [ "def marker_factory(loc, popup, is_public=True):\n", " std_tooltip = 'Click for more information'\n", " std_icon = icon_factory(is_public)\n", " return folium.Marker(loc, popup=popup, icon=std_icon, tooltip=std_tooltip)" ] }, { "cell_type": "markdown", "id": "1e7f7f3a-d234-427d-ad06-3026c00312a4", "metadata": { "nbgrader": { "grade": false, "grade_id": "cell-2b6d551c3e806181", "locked": true, "schema_version": 3, "solution": false, "task": false } }, "source": [ "With these two functions it is now easy to replicate the map created in the previous chapter:" ] }, { "cell_type": "code", "execution_count": 21, "id": "6a60ccee-4728-4bf1-93db-1158deae037f", "metadata": { "nbgrader": { "grade": false, "grade_id": "cell-7166c54f214ed13e", "locked": true, "schema_version": 3, "solution": false, "task": false } }, "outputs": [ { "data": { "text/html": [ "
Make this Notebook Trusted to load map: File -> Trust Notebook
" ], "text/plain": [ "" ] }, "execution_count": 21, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Create Map\n", "m = folium.Map(\n", " location=(52.258, 10.5),\n", " tiles='OpenStreetMap',\n", " zoom_start=16,\n", " prefer_canvas=False\n", " )\n", "\n", "# Define popup\n", "pp = popup_factory(\n", " adr='Johannes-Selenka-Platz 1',\n", " zipc='38118 Braunschweig',\n", " country='Germany, DE',\n", " pic=\"https://www.hbk-bs.de/fileadmin/_processed_/5/1/csm_HBK_Logo_9f3f898a2b.png\",\n", " )\n", "\n", "# Define Marker\n", "marker = marker_factory(\n", " loc=(52.257770, 10.502490),\n", " popup=pp\n", " )\n", "\n", "# Attach Marker to Map\n", "marker.add_to(m)\n", "\n", "# Display Map\n", "m" ] }, { "cell_type": "markdown", "id": "1110a947-36cb-43c8-9348-fe3bafabe185", "metadata": { "nbgrader": { "grade": false, "grade_id": "cell-a1045f8d87d79df5", "locked": true, "schema_version": 3, "solution": false, "task": false } }, "source": [ "# Exercise 3: Mapping the Universties in Lower Saxony\n", "\n", "## 3.1: Reading the Dataset\n", "The data set for this notebook is *unis_nd.csv*.\n", "\n", "Read this into the variable `df` using the _pandas_ `read_csv` function.\n", "\n", "(I recommend that you take a look at the data set)" ] }, { "cell_type": "code", "execution_count": 22, "id": "b50d076d-4b5f-4137-93df-846144b119b7", "metadata": { "nbgrader": { "grade": false, "grade_id": "cell-c55c41f6b9c03dd6", "locked": true, "schema_version": 3, "solution": false, "task": false } }, "outputs": [], "source": [ "import pandas as pd" ] }, { "cell_type": "code", "execution_count": 23, "id": "16c81c07-5893-42a7-9b1d-a081deea998c", "metadata": { "nbgrader": { "grade": false, "grade_id": "cell-d58de9c13e900a3b", "locked": false, "schema_version": 3, "solution": true, "task": false }, "tags": [] }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
University nameType of universitySponsorshipRight of promotionFounding yearNumber of studentsAddresslatlonplzpic
0Hochschule für Bildende Künste BraunschweigArtistic universitypublicyes1963976.000Johannes-Selenka-Platz 152.25773810.50231538118 Braunschweighttps://www.hbk-bs.de/fileadmin/_processed_/5/...
1Technische Universität Carolo-Wilhelmina zu Br...Universitypublicyes174517709.000Universitätspl. 252.27355010.53009738106 Braunschweighttps://upload.wikimedia.org/wikipedia/commons...
2Hochschule 21University of Applied Sciencesprivatno20051084.000Harburger Str. 653.4776509.70465021614 Buxtehudehttps://upload.wikimedia.org/wikipedia/commons...
3Technische Universität ClausthalUniversitypublicyes17753446.000Adolph-Roemer-Straße 2A51.80484010.33411038678 Clausthal-Zellerfeldhttps://www.presse.tu-clausthal.de/fileadmin/T...
4Hochschule Emden/LeerUniversity of Applied Sciencespublicno20094481.000Constantiapl. 453.3681607.18141026723 Emdenhttps://sta-hisweb.hs-emden-leer.de/QIS/images...
5PFH – Private Hochschule GöttingenUniversity of Applied Sciencesprivatno19954226.000Weender Landstraße 3-751.5389109.93322037073 Göttingenhttps://goettingen-campus.de/fileadmin/_proces...
6Georg-August-Universität GöttingenUniversitypublicyes173728614.000Wilhelmsplatz 151.5340709.93785037073 Göttingenhttps://upload.wikimedia.org/wikipedia/commons...
7Fachhochschule für die Wirtschaft HannoverUniversity of Applied Sciencesprivatno1996641.000Freundallee 1552.3662009.77247030173 Hannoverhttps://upload.wikimedia.org/wikipedia/commons...
8Hochschule HannoverUniversity of Applied Sciencespublicno19719209.000Ricklinger Stadtweg 12052.3541909.72238030459 Hannoverhttps://upload.wikimedia.org/wikipedia/commons...
9Hochschule für Musik, Theater und Medien HannoverArtistic universitypublicyes18971409.000Neues Haus 152.3773809.75392030175 Hannoverhttps://upload.wikimedia.org/wikipedia/commons...
10Leibniz-FachhochschuleUniversity of Applied Sciencesprivatno1920589.000Expo Plaza 1152.3211509.81868030539 Hannoverhttps://www.visit-hannover.com/var/storage/ima...
11Medizinische Hochschule Hannover (MHH)Universitypublicyes19633778.000Carl-Neuberg-Straße 152.3840509.80603030625 Hannoverhttps://upload.wikimedia.org/wikipedia/commons...
12Stiftung Tierärztliche Hochschule HannoverUniversitypublicyes17782381.000Bünteweg 252.3546809.79773030559 Hannoverhttps://upload.wikimedia.org/wikipedia/de/thum...
13Gottfried Wilhelm Leibniz Universität HannoverUniversitypublicyes183128935.000Welfengarten 152.3822509.71777030167 Hannoverhttps://www.uni-hannover.de/fileadmin/_process...
14Fachhochschule für Interkulturelle Theologie H...University of Applied Sciencesprivatno201291.000Missionsstraße 3-552.70884310.14071029320 Südheidehttps://cdn.max-e5.info/damfiles/logo/fh_herma...
15Universität HildesheimUniversitypublicyes19788378.000Universitätspl. 152.1340109.97469031141 Hildesheimhttps://www.uni-hildesheim.de/media/_processed...
16HAWK Hochschule für angewandte Wissenschaft un...University of Applied Sciencespublicno19716495.000Hohnsen 452.1424609.95798031134 Hildesheimhttps://upload.wikimedia.org/wikipedia/commons...
17HAWK Hochschule für angewandte Wissenschaft un...University of Applied Sciencespublicno19716495.000Haarmannpl. 351.8272609.45069037603 Holzmindenhttps://upload.wikimedia.org/wikipedia/commons...
18HAWK Hochschule für angewandte Wissenschaft un...University of Applied Sciencespublicno19716495.000Von-Ossietzky-Straße 9951.5217509.96967037085 Göttingenhttps://upload.wikimedia.org/wikipedia/commons...
19Leuphana Universität LüneburgUniversitypublicyes19466497.000Universitätsallee 153.22853110.40171021335 Lüneburghttps://upload.wikimedia.org/wikipedia/commons...
20Norddeutsche Hochschule für Rechtspflege – Nie...University of Administrationpublicno20076409.000Godehardspl. 652.1448409.94923031134 Hildesheimhttps://static.studycheck.de/media/images/inst...
21Kommunale Hochschule für Verwaltung in Nieders...University of Administrationpublicno20071570.000Wielandstraße 852.3705009.72239030169 Hannoverhttps://www.nsi-hsvn.de/fileadmin/user_upload/...
22Carl von Ossietzky Universität Oldenburg\\nUniversitypublicyes197315635.000Uhlhornsweg 49-5553.1473408.17902026129 Oldenburghttps://upload.wikimedia.org/wikipedia/commons...
23Hochschule OsnabrückUniversity of Applied Sciencespublicno197113620.000Albrechtstraße 3052.2826808.02501049076 Osnabrückhttps://login.hs-osnabrueck.de/nidp/hsos/image...
24Universität OsnabrückUniversitypublicyes197313640.000Neuer Graben 2952.2713708.04454049074 Osnabrückhttps://www.eh-tabor.de/sites/default/files/st...
25Hochschule Braunschweig/Wolfenbüttel, Ostfalia...University of Applied Sciencespublicno197111577.000Salzdahlumer Str. 46/4852.17683010.54865038302 Wolfenbüttelhttps://www.ostfalia.de/export/system/modules/...
26Hochschule Wolfsburg, Ostfalia Hochschule für ...University of Applied Sciencespublicno197111577.000Robert-Koch-Platz 8A52.42595010.78711038440 Wolfsburghttps://www.ostfalia.de/export/system/modules/...
27Hochschule Suderburg, Ostfalia Hochschule für ...University of Applied Sciencespublicno197111577.000Herbert-Meyer-Straße 752.89761010.44659029556 Suderburghttps://www.ostfalia.de/export/system/modules/...
28Hochschule Salzgitter, Ostfalia Hochschule für...University of Applied Sciencespublicno197111577.000Karl-Scharfenberg-Straße 55/5752.08724010.38055038229 Salzgitterhttps://www.ostfalia.de/export/system/modules/...
29Hochschule für Künste im Sozialen, OttersbergUniversity of Applied Sciencesprivatno1967342.000Große Str. 10753.1066809.16310028870 Ottersberghttps://upload.wikimedia.org/wikipedia/commons...
30Private Hochschule für Wirtschaft und Technik ...University of Applied Sciencesprivatno1998558.000Rombergstraße 4052.7212508.27891049377 Vechtahttps://www.phwt.de/wp-content/uploads/2020/09...
31Private Hochschule für Wirtschaft und Technik ...University of Applied Sciencesprivatno1998558.000Schlesier Str. 13A52.6117108.36334049356 Diepholzhttps://www.phwt.de/wp-content/uploads/2020/09...
32Universität VechtaUniversitypublicyes19954.551Driverstraße 2252.7211708.29380049377 Vechtahttps://upload.wikimedia.org/wikipedia/commons...
33Hochschule WeserberglandUniversity of Applied Sciencesprivatno2010485.000Am Stockhof 252.0987509.35542031785 Hamelnhttps://upload.wikimedia.org/wikipedia/commons...
34Jade Hochschule – WilhelmshavenUniversity of Applied Sciencespublicno20096789.000Friedrich-Paffrath-Straße 10153.5478708.08804026389 Wilhelmshavenhttps://www.jade-hs.de/fileadmin/layout2016/as...
35Jade Hochschule – OldenburgUniversity of Applied Sciencespublicno20096789.000Ofener Str. 16/1953.1417908.20213026121 Oldenburghttps://www.jade-hs.de/fileadmin/layout2016/as...
36Jade Hochschule – ElsflethUniversity of Applied Sciencespublicno20096789.000Weserstraße 5253.2424408.46651026931 Elsflethhttps://www.jade-hs.de/fileadmin/layout2016/as...
37Steuerakademie Niedersachsen RintelnUniversity of Administrationpublicno2006500.000Wilhelm-Busch-Weg 2952.2069609.09112031737 Rintelnhttps://www.steuerakademie.niedersachsen.de/as...
38Steuerakademie Niedersachsen Bad EilsenUniversity of Administrationpublicno2006500.000Bahnhofstraße 552.2398109.10423031707 Bad Eilsenhttps://www.steuerakademie.niedersachsen.de/as...
\n", "
" ], "text/plain": [ " University name \\\n", "0 Hochschule für Bildende Künste Braunschweig \n", "1 Technische Universität Carolo-Wilhelmina zu Br... \n", "2 Hochschule 21 \n", "3 Technische Universität Clausthal \n", "4 Hochschule Emden/Leer \n", "5 PFH – Private Hochschule Göttingen \n", "6 Georg-August-Universität Göttingen \n", "7 Fachhochschule für die Wirtschaft Hannover \n", "8 Hochschule Hannover \n", "9 Hochschule für Musik, Theater und Medien Hannover \n", "10 Leibniz-Fachhochschule \n", "11 Medizinische Hochschule Hannover (MHH) \n", "12 Stiftung Tierärztliche Hochschule Hannover \n", "13 Gottfried Wilhelm Leibniz Universität Hannover \n", "14 Fachhochschule für Interkulturelle Theologie H... \n", "15 Universität Hildesheim \n", "16 HAWK Hochschule für angewandte Wissenschaft un... \n", "17 HAWK Hochschule für angewandte Wissenschaft un... \n", "18 HAWK Hochschule für angewandte Wissenschaft un... \n", "19 Leuphana Universität Lüneburg \n", "20 Norddeutsche Hochschule für Rechtspflege – Nie... \n", "21 Kommunale Hochschule für Verwaltung in Nieders... \n", "22 Carl von Ossietzky Universität Oldenburg\\n \n", "23 Hochschule Osnabrück \n", "24 Universität Osnabrück \n", "25 Hochschule Braunschweig/Wolfenbüttel, Ostfalia... \n", "26 Hochschule Wolfsburg, Ostfalia Hochschule für ... \n", "27 Hochschule Suderburg, Ostfalia Hochschule für ... \n", "28 Hochschule Salzgitter, Ostfalia Hochschule für... \n", "29 Hochschule für Künste im Sozialen, Ottersberg \n", "30 Private Hochschule für Wirtschaft und Technik ... \n", "31 Private Hochschule für Wirtschaft und Technik ... \n", "32 Universität Vechta \n", "33 Hochschule Weserbergland \n", "34 Jade Hochschule – Wilhelmshaven \n", "35 Jade Hochschule – Oldenburg \n", "36 Jade Hochschule – Elsfleth \n", "37 Steuerakademie Niedersachsen Rinteln \n", "38 Steuerakademie Niedersachsen Bad Eilsen \n", "\n", " Type of university Sponsorship Right of promotion \\\n", "0 Artistic university public yes \n", "1 University public yes \n", "2 University of Applied Sciences privat no \n", "3 University public yes \n", "4 University of Applied Sciences public no \n", "5 University of Applied Sciences privat no \n", "6 University public yes \n", "7 University of Applied Sciences privat no \n", "8 University of Applied Sciences public no \n", "9 Artistic university public yes \n", "10 University of Applied Sciences privat no \n", "11 University public yes \n", "12 University public yes \n", "13 University public yes \n", "14 University of Applied Sciences privat no \n", "15 University public yes \n", "16 University of Applied Sciences public no \n", "17 University of Applied Sciences public no \n", "18 University of Applied Sciences public no \n", "19 University public yes \n", "20 University of Administration public no \n", "21 University of Administration public no \n", "22 University public yes \n", "23 University of Applied Sciences public no \n", "24 University public yes \n", "25 University of Applied Sciences public no \n", "26 University of Applied Sciences public no \n", "27 University of Applied Sciences public no \n", "28 University of Applied Sciences public no \n", "29 University of Applied Sciences privat no \n", "30 University of Applied Sciences privat no \n", "31 University of Applied Sciences privat no \n", "32 University public yes \n", "33 University of Applied Sciences privat no \n", "34 University of Applied Sciences public no \n", "35 University of Applied Sciences public no \n", "36 University of Applied Sciences public no \n", "37 University of Administration public no \n", "38 University of Administration public no \n", "\n", " Founding year Number of students Address \\\n", "0 1963 976.000 Johannes-Selenka-Platz 1 \n", "1 1745 17709.000 Universitätspl. 2 \n", "2 2005 1084.000 Harburger Str. 6 \n", "3 1775 3446.000 Adolph-Roemer-Straße 2A \n", "4 2009 4481.000 Constantiapl. 4 \n", "5 1995 4226.000 Weender Landstraße 3-7 \n", "6 1737 28614.000 Wilhelmsplatz 1 \n", "7 1996 641.000 Freundallee 15 \n", "8 1971 9209.000 Ricklinger Stadtweg 120 \n", "9 1897 1409.000 Neues Haus 1 \n", "10 1920 589.000 Expo Plaza 11 \n", "11 1963 3778.000 Carl-Neuberg-Straße 1 \n", "12 1778 2381.000 Bünteweg 2 \n", "13 1831 28935.000 Welfengarten 1 \n", "14 2012 91.000 Missionsstraße 3-5 \n", "15 1978 8378.000 Universitätspl. 1 \n", "16 1971 6495.000 Hohnsen 4 \n", "17 1971 6495.000 Haarmannpl. 3 \n", "18 1971 6495.000 Von-Ossietzky-Straße 99 \n", "19 1946 6497.000 Universitätsallee 1 \n", "20 2007 6409.000 Godehardspl. 6 \n", "21 2007 1570.000 Wielandstraße 8 \n", "22 1973 15635.000 Uhlhornsweg 49-55 \n", "23 1971 13620.000 Albrechtstraße 30 \n", "24 1973 13640.000 Neuer Graben 29 \n", "25 1971 11577.000 Salzdahlumer Str. 46/48 \n", "26 1971 11577.000 Robert-Koch-Platz 8A \n", "27 1971 11577.000 Herbert-Meyer-Straße 7 \n", "28 1971 11577.000 Karl-Scharfenberg-Straße 55/57 \n", "29 1967 342.000 Große Str. 107 \n", "30 1998 558.000 Rombergstraße 40 \n", "31 1998 558.000 Schlesier Str. 13A \n", "32 1995 4.551 Driverstraße 22 \n", "33 2010 485.000 Am Stockhof 2 \n", "34 2009 6789.000 Friedrich-Paffrath-Straße 101 \n", "35 2009 6789.000 Ofener Str. 16/19 \n", "36 2009 6789.000 Weserstraße 52 \n", "37 2006 500.000 Wilhelm-Busch-Weg 29 \n", "38 2006 500.000 Bahnhofstraße 5 \n", "\n", " lat lon plz \\\n", "0 52.257738 10.502315 38118 Braunschweig \n", "1 52.273550 10.530097 38106 Braunschweig \n", "2 53.477650 9.704650 21614 Buxtehude \n", "3 51.804840 10.334110 38678 Clausthal-Zellerfeld \n", "4 53.368160 7.181410 26723 Emden \n", "5 51.538910 9.933220 37073 Göttingen \n", "6 51.534070 9.937850 37073 Göttingen \n", "7 52.366200 9.772470 30173 Hannover \n", "8 52.354190 9.722380 30459 Hannover \n", "9 52.377380 9.753920 30175 Hannover \n", "10 52.321150 9.818680 30539 Hannover \n", "11 52.384050 9.806030 30625 Hannover \n", "12 52.354680 9.797730 30559 Hannover \n", "13 52.382250 9.717770 30167 Hannover \n", "14 52.708843 10.140710 29320 Südheide \n", "15 52.134010 9.974690 31141 Hildesheim \n", "16 52.142460 9.957980 31134 Hildesheim \n", "17 51.827260 9.450690 37603 Holzminden \n", "18 51.521750 9.969670 37085 Göttingen \n", "19 53.228531 10.401710 21335 Lüneburg \n", "20 52.144840 9.949230 31134 Hildesheim \n", "21 52.370500 9.722390 30169 Hannover \n", "22 53.147340 8.179020 26129 Oldenburg \n", "23 52.282680 8.025010 49076 Osnabrück \n", "24 52.271370 8.044540 49074 Osnabrück \n", "25 52.176830 10.548650 38302 Wolfenbüttel \n", "26 52.425950 10.787110 38440 Wolfsburg \n", "27 52.897610 10.446590 29556 Suderburg \n", "28 52.087240 10.380550 38229 Salzgitter \n", "29 53.106680 9.163100 28870 Ottersberg \n", "30 52.721250 8.278910 49377 Vechta \n", "31 52.611710 8.363340 49356 Diepholz \n", "32 52.721170 8.293800 49377 Vechta \n", "33 52.098750 9.355420 31785 Hameln \n", "34 53.547870 8.088040 26389 Wilhelmshaven \n", "35 53.141790 8.202130 26121 Oldenburg \n", "36 53.242440 8.466510 26931 Elsfleth \n", "37 52.206960 9.091120 31737 Rinteln \n", "38 52.239810 9.104230 31707 Bad Eilsen \n", "\n", " pic \n", "0 https://www.hbk-bs.de/fileadmin/_processed_/5/... \n", "1 https://upload.wikimedia.org/wikipedia/commons... \n", "2 https://upload.wikimedia.org/wikipedia/commons... \n", "3 https://www.presse.tu-clausthal.de/fileadmin/T... \n", "4 https://sta-hisweb.hs-emden-leer.de/QIS/images... \n", "5 https://goettingen-campus.de/fileadmin/_proces... \n", "6 https://upload.wikimedia.org/wikipedia/commons... \n", "7 https://upload.wikimedia.org/wikipedia/commons... \n", "8 https://upload.wikimedia.org/wikipedia/commons... \n", "9 https://upload.wikimedia.org/wikipedia/commons... \n", "10 https://www.visit-hannover.com/var/storage/ima... \n", "11 https://upload.wikimedia.org/wikipedia/commons... \n", "12 https://upload.wikimedia.org/wikipedia/de/thum... \n", "13 https://www.uni-hannover.de/fileadmin/_process... \n", "14 https://cdn.max-e5.info/damfiles/logo/fh_herma... \n", "15 https://www.uni-hildesheim.de/media/_processed... \n", "16 https://upload.wikimedia.org/wikipedia/commons... \n", "17 https://upload.wikimedia.org/wikipedia/commons... \n", "18 https://upload.wikimedia.org/wikipedia/commons... \n", "19 https://upload.wikimedia.org/wikipedia/commons... \n", "20 https://static.studycheck.de/media/images/inst... \n", "21 https://www.nsi-hsvn.de/fileadmin/user_upload/... \n", "22 https://upload.wikimedia.org/wikipedia/commons... \n", "23 https://login.hs-osnabrueck.de/nidp/hsos/image... \n", "24 https://www.eh-tabor.de/sites/default/files/st... \n", "25 https://www.ostfalia.de/export/system/modules/... \n", "26 https://www.ostfalia.de/export/system/modules/... \n", "27 https://www.ostfalia.de/export/system/modules/... \n", "28 https://www.ostfalia.de/export/system/modules/... \n", "29 https://upload.wikimedia.org/wikipedia/commons... \n", "30 https://www.phwt.de/wp-content/uploads/2020/09... \n", "31 https://www.phwt.de/wp-content/uploads/2020/09... \n", "32 https://upload.wikimedia.org/wikipedia/commons... \n", "33 https://upload.wikimedia.org/wikipedia/commons... \n", "34 https://www.jade-hs.de/fileadmin/layout2016/as... \n", "35 https://www.jade-hs.de/fileadmin/layout2016/as... \n", "36 https://www.jade-hs.de/fileadmin/layout2016/as... \n", "37 https://www.steuerakademie.niedersachsen.de/as... \n", "38 https://www.steuerakademie.niedersachsen.de/as... " ] }, "execution_count": 23, "metadata": {}, "output_type": "execute_result" } ], "source": [ "### BEGIN SOLUTION\n", "df = pd.read_csv('unis_nd.csv')\n", "df\n", "### END SOLUTION" ] }, { "cell_type": "code", "execution_count": 24, "id": "a30598a7-c7d4-42cc-a9b8-dc6356d060aa", "metadata": { "nbgrader": { "grade": true, "grade_id": "cell-3e80e16a38e85d29", "locked": true, "points": 1, "schema_version": 3, "solution": false, "task": false } }, "outputs": [], "source": [ "# Your Solutions are tested here..\n", "assert isinstance(df, pd.DataFrame)" ] }, { "cell_type": "markdown", "id": "da44f50f-0c2d-404d-8083-289742c5497a", "metadata": { "nbgrader": { "grade": false, "grade_id": "cell-237bfc25448676b2", "locked": true, "schema_version": 3, "solution": false, "task": false } }, "source": [ "## 3.2: Defining the Map\n", "\n", "Before we plot the dataset, define a map with the name `lower_saxony`. \n", "\n", "- The location should be the georaphic centre of Lower Saxony in _Wehrenberg 27318 Hoyerhagen_ `(52.806390, 9.135110)`.\n", "- Use a suitable tileset from the documentation\n", "- Use a suitable zoom setting" ] }, { "cell_type": "code", "execution_count": 25, "id": "bfe04668-a597-4f93-b6e4-11ef17d18dcd", "metadata": { "nbgrader": { "grade": false, "grade_id": "cell-0d7c995b3fcc368e", "locked": false, "schema_version": 3, "solution": true, "task": false } }, "outputs": [], "source": [ "### BEGIN SOLUTION\n", "lower_saxony = folium.Map(\n", " location=(52.806390, 9.135110), # Georaphical centre Point of Lower Saxony Wehrenberg 27318 Hoyerhagen\n", " tiles='OpenStreetMap',\n", " zoom_start=7\n", " )\n", "### END SOLUTION" ] }, { "cell_type": "code", "execution_count": 26, "id": "a2f05ce6-7942-4c71-b1e2-a709c88b0f36", "metadata": { "nbgrader": { "grade": true, "grade_id": "cell-77f8257bb3c1308f", "locked": true, "points": 4, "schema_version": 3, "solution": false, "task": false } }, "outputs": [], "source": [ "# Your Solutions are tested here..\n", "assert isinstance(lower_saxony, folium.Map)\n", "assert len(lower_saxony.location) == 2" ] }, { "cell_type": "markdown", "id": "357c71bb-923a-4de6-bcbd-b9d2741498fc", "metadata": { "nbgrader": { "grade": false, "grade_id": "cell-d66a439bbfb3778a", "locked": true, "schema_version": 3, "solution": false, "task": false } }, "source": [ "## 3.3 Plotting the Dataset\n", "\n", "Write a for loop which reads the values from the dataset `df` and add the markers to the map `lower_saxony` using the already defined functions `popup_factory` and `marker_factory`. " ] }, { "cell_type": "code", "execution_count": 27, "id": "b392f48f-f0ae-4158-806f-859e71009c04", "metadata": { "nbgrader": { "grade": true, "grade_id": "cell-b744358aaaa7db44", "locked": false, "points": 5, "schema_version": 3, "solution": true, "task": false } }, "outputs": [ { "data": { "text/html": [ "
Make this Notebook Trusted to load map: File -> Trust Notebook
" ], "text/plain": [ "" ] }, "execution_count": 27, "metadata": {}, "output_type": "execute_result" } ], "source": [ "### BEGIN SOLUTION\n", "for index, row in df.iterrows():\n", " pp = popup_factory(\n", " adr=row['Address'],\n", " zipc=row['plz'],\n", " country='Germany, DE',\n", " pic=row['pic'],\n", " )\n", " location = (float(row['lat']), float(row['lon']))\n", " \n", " is_public = False\n", " if row['Sponsorship'] == 'public':\n", " is_public = True\n", " \n", " marker = marker_factory(location, pp, is_public) \n", " marker.add_to(lower_saxony)\n", " \n", "lower_saxony\n", "### END SOLUTION" ] }, { "cell_type": "code", "execution_count": 28, "id": "ab37a764-3718-4327-976c-146e5531a048", "metadata": { "nbgrader": { "grade": false, "grade_id": "cell-49864685eac331d1", "locked": true, "schema_version": 3, "solution": false, "task": false } }, "outputs": [ { "data": { "text/html": [ "
Make this Notebook Trusted to load map: File -> Trust Notebook
" ], "text/plain": [ "" ] }, "execution_count": 28, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Your Solutions are tested and displayed here..\n", "lower_saxony" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "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.12.7" }, "toc-autonumbering": false }, "nbformat": 4, "nbformat_minor": 5 }