{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Welcome to the Mobile & Web Mapping Lab - Session 2!\n",
    "\n",
    "[![Binder](http://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/anitagraser/ogd-at-lab/main?urlpath=lab/tree/notebooks/webmapping.ipynb)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Recap of session 1\n",
    "\n",
    "### Data collection & presentation as essential parts of geographic data science\n",
    "\n",
    "![](./img/datascience.png)\n",
    "\n",
    "*Figure: Data science workflow (Graser & Dragaschnig 2020).*\n",
    "\n",
    "### Intro to webmapping \n",
    "\n",
    "\n",
    "![](./img/architecture.jpg)\n",
    "\n",
    "*Figure: Typical web mapping architecture (Brovelli et al. 2013).*\n",
    "\n",
    "<br/>\n",
    "<br/>\n",
    "<br/>\n",
    "\n",
    "<hr>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Session 2: Webmapping services - more than just maps in a browser\n",
    "\n",
    "**Today's goals**\n",
    "\n",
    "* Understanding different types of web map service standards\n",
    "* Exploring other useful non-standard service examples\n",
    "\n",
    "<br/>\n",
    "<br/>\n",
    "<br/>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    " \n",
    "### 1. Tiles / basemaps\n",
    "\n",
    "**Use case:** Map background / geographic context\n",
    "\n",
    "**Standard:** Web Map Tile Services (WMTS) / XYZ Tiles\n",
    "\n",
    "\n",
    "<br/>\n",
    "<br/>\n",
    "<br/>\n",
    "\n",
    "Basemap tiles are everywhere ...\n",
    "\n",
    "#### In desktop GIS, e.g. QGIS\n",
    "\n",
    "![](./img/osm-qgis.PNG)\n",
    "\n",
    "*Figure: OSM Tiles in QGIS*\n",
    "\n",
    "<br/>\n",
    "<br/>\n",
    "<br/>\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "\n",
    "#### In web maps, e.g. Leaflet\n",
    "\n",
    "![](./img/leaflet.PNG)\n",
    "\n",
    "*Figure: OSM Tiles in Leaflet*\n",
    "\n",
    "<br/>\n",
    "<br/>\n",
    "<br/>\n",
    "\n",
    "#### In notebooks, e.g. Geoviews & Bokeh"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import holoviews as hv\n",
    "import geoviews as gv\n",
    "gv.extension('bokeh')\n",
    "\n",
    "basemap = hv.element.tiles.OSM().opts(width=450, height=450)\n",
    "basemap"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Documentation:  http://geoviews.org/user_guide/Working_with_Bokeh.html\n",
    "\n",
    "<br/>\n",
    "<br/>\n",
    "<br/>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 2. Raster maps\n",
    "\n",
    "**Use case:** Cartographic products (e.g. hillshades, topographic maps), map overlays ...\n",
    "\n",
    "**Standard:** Web Map Services (WMS) \n",
    "\n",
    "<br/>\n",
    "<br/>\n",
    "<br/>\n",
    "\n",
    "#### In desktop GIS, e.g. QGIS\n",
    "\n",
    "![](./img/wms-qgis.PNG)\n",
    "\n",
    "*Figure: WMS layers in QGIS*\n",
    "\n",
    "<br/>\n",
    "<br/>\n",
    "<br/>\n",
    "\n",
    "#### In notebooks, e.g. Geoviews & Bokeh"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "url = \"\"\"\n",
    "http://data.wien.gv.at/daten/geo?\n",
    "&service=WMS\n",
    "&request=GetMap\n",
    "&layers=ogdwien:DONAUINSPKTOGD\n",
    "&styles=\n",
    "&format=image/png\n",
    "&transparent=true\n",
    "&version=1.3.0\n",
    "&width=256\n",
    "&height=256\n",
    "&crs=EPSG:3857\n",
    "&bbox={XMIN},{YMIN},{XMAX},{YMAX}\n",
    "\"\"\"\n",
    "\n",
    "basemap = hv.element.tiles.OSM().opts(width=450, height=450)\n",
    "map_with_overlay = basemap * hv.Tiles(url, extents=(1825290,6144246,1827693,6146435))\n",
    "map_with_overlay"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "url2 = \"\"\"\n",
    "http://data.wien.gv.at/daten/geo?\n",
    "&service=WMS\n",
    "&request=GetMap\n",
    "&layers=ogdwien:DONAUKILOMETEROGD\n",
    "&styles=\n",
    "&format=image/png\n",
    "&transparent=true\n",
    "&version=1.3.0\n",
    "&width=256\n",
    "&height=256\n",
    "&crs=EPSG:3857\n",
    "&bbox={XMIN},{YMIN},{XMAX},{YMAX}\n",
    "\"\"\"\n",
    "\n",
    "map_with_overlay * hv.Tiles(url2, extents=(1825290,6144246,1827693,6146435))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Source: https://github.com/holoviz/geoviews/issues/481\n",
    "\n",
    "<br/>\n",
    "<br/>\n",
    "<br/>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 3. Vector data\n",
    "\n",
    "**Use case:** Access to geometry and attribute data\n",
    "\n",
    "**Standard:** Web Feature Services (WFS) \n",
    "\n",
    "<br/>\n",
    "<br/>\n",
    "<br/>\n",
    "\n",
    "#### In desktop GIS, e.g. QGIS\n",
    "\n",
    "![](./img/wfs-qgis.PNG)\n",
    "\n",
    "*Figure: WFS layer in QGIS*\n",
    "\n",
    "<br/>\n",
    "<br/>\n",
    "<br/>\n",
    "\n",
    "#### In notebooks, e.g. Geoviews & Bokeh"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import geopandas as gpd\n",
    "from urllib.request import urlretrieve\n",
    "import hvplot.pandas\n",
    "\n",
    "layer = 'CITYBIKEOGD'\n",
    "file = f'data/{layer}.json'\n",
    "url = f\"https://data.wien.gv.at/daten/geo?service=WFS&request=GetFeature&version=1.1.0&typeName=ogdwien:{layer}&srsName=EPSG:4326&outputFormat=json\"\n",
    "urlretrieve(url, file)\n",
    "gdf = gpd.read_file(file)\n",
    "gdf"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "gdf.hvplot(geo=True, tiles='OSM', hover_cols=['STATION']).opts(active_tools=['wheel_zoom'])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 4. Other non-standard service examples\n",
    "\n",
    "1. [Geocoding addresses with Nominatim](geocoding.ipynb)\n",
    "1. [Getting elevation information](elevation.ipynb)\n",
    "\n",
    "<br/>\n",
    "<br/>\n",
    "<br/>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## References\n",
    "\n",
    "* Brovelli, M., Minghini, M., & Zamboni, G. (2013). Web–based Participatory GIS with data collection on the field–A prototype architecture. In Free and Open Source Software for Geospatial (FOSS4G) Conference Proceedings (Vol. 13, No. 1, p. 5).\n",
    "* Graser, A. & Dragaschnig, M. (2020). Open Geospatial Tools for Movement Data Exploration. KN ‒ Journal of Cartography and Geographic Information, 70(1), 3-10. doi:10.1007/s42489-020-00039-y."
   ]
  }
 ],
 "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.7.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
