{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "8172e00a-5678-44c3-894b-ce92e0bf9156",
   "metadata": {},
   "source": [
    "# Python and VGI - 01/06: OHSOME Building Development"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "844fdf4e-fdbf-40bd-b21f-fb8d42345021",
   "metadata": {},
   "source": [
    "***"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c498c160",
   "metadata": {},
   "outputs": [],
   "source": [
    "# import the ohsome package\n",
    "from ohsome import OhsomeClient"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "cb4c2e6e-bf84-431d-b2e6-f77af0c01b99",
   "metadata": {},
   "outputs": [],
   "source": [
    "import matplotlib"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "70204539",
   "metadata": {},
   "outputs": [],
   "source": [
    "client = OhsomeClient()\n",
    "client.base_api_url\n",
    "client.start_timestamp # --> '2007-10-08T00:00:00Z'\n",
    "client.end_timestamp # --> '2021-01-23T03:00Z'\n",
    "client.api_version"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "67d760ba-9853-460c-92d0-062dc82e928c",
   "metadata": {},
   "source": [
    "# Development of mapped buildings"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "323ebf51",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Define AOI-Box by using coordinates\n",
    "bboxes = [7.24122,51.45557,7.28003,51.43241]\n",
    "\n",
    "# Define time scale\n",
    "time = \"2010-01-01/2020-05-05/P1M\"\n",
    "\n",
    "# Filter for desired features\n",
    "fltr = \"building=* and type:way\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2aabfa85",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "# Plot the number of buildings within your set AOI\n",
    "response = client.elements.count.post(bboxes=bboxes,\n",
    "                                      time=time, \n",
    "                                      filter=fltr)\n",
    "response_df = response.as_dataframe()\n",
    "response_df.plot(ylabel=\"Number of buildings in AOI Bochum Querenburg (2010-2020)\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4f4862a0",
   "metadata": {},
   "source": [
    "# Development of COVID-19 vaccination centres"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "72af45bf",
   "metadata": {},
   "outputs": [],
   "source": [
    "bbox = [5.778809,47.234490,15.161133,55.416544] #Roughly Germany\n",
    "\n",
    "# Setting the time for your investigation\n",
    "time = \"2020-12-01/2021-07-15/P1D\" #with an interval of 1 day\n",
    "\n",
    "# Filter for desired variable\n",
    "fltr = \"vaccination=covid19 and type:node\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7b468110",
   "metadata": {},
   "outputs": [],
   "source": [
    "response = client.elements.count.post(bboxes=bbox, time=time, filter=fltr)\n",
    "response_df = response.as_dataframe()\n",
    "response_df.plot(ylabel=\"Number of COVID-19 vaccination centres\")"
   ]
  }
 ],
 "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.8.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
