{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "a1aa3974-2590-4c35-8278-29bf8269a3b5",
   "metadata": {},
   "outputs": [],
   "source": [
    "import duckdb\n",
    "from lonboard import viz"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "68fc8e11-6463-4ad5-b70e-61910cb6cfbe",
   "metadata": {},
   "outputs": [],
   "source": [
    "con = duckdb.connect()\n",
    "con.install_extension(\"spatial\")\n",
    "con.load_extension(\"spatial\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "10c0d819-c86a-4c6c-afed-396136685d0d",
   "metadata": {},
   "source": [
    "# 2021 Dissemination Blocks"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "7d7ee1da-4fa7-4d66-bac1-b2e384bd4110",
   "metadata": {},
   "outputs": [],
   "source": [
    "sql = \"SELECT * FROM 'https://data.dataforcanada.org/processed/statistics_canada/boundaries/2021/cartographic_boundary_files/db_2021.parquet';\"\n",
    "query = con.sql(sql)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "da57c688-ca49-4fa7-8178-58e0cc9cb351",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "7f9788d8a56e4d4fa46b84081cd1f0c6",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "FloatProgress(value=0.0, layout=Layout(width='auto'), style=ProgressStyle(bar_color='black'))"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "8fa8cd4e3bfd4cd3bc7fd8e699b21c5d",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "FloatProgress(value=0.0, layout=Layout(width='auto'), style=ProgressStyle(bar_color='black'))"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/root/.venv/lib/python3.12/site-packages/lonboard/_geoarrow/ops/reproject.py:33: UserWarning: No CRS exists on data. If no data is shown on the map, double check that your CRS is WGS84.\n",
      "  warn(\n"
     ]
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "5fc5f6aca9b949c6b21987130d06e637",
       "version_major": 2,
       "version_minor": 1
      },
      "text/plain": [
       "Map(basemap_style=<CartoBasemap.DarkMatter: 'https://basemaps.cartocdn.com/gl/dark-matter-gl-style/style.json'…"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "viz(query, con=con)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3efc0288-73ea-4b19-b0d1-261c863bf330",
   "metadata": {},
   "source": [
    "# 2021 Road Network File"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "70b951ad-9b8f-47b6-ad6d-8f6e2ae77a56",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "c8a8cc73329d41209f43a7f94e4e561a",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "FloatProgress(value=0.0, layout=Layout(width='auto'), style=ProgressStyle(bar_color='black'))"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "65f8ad04cc0a4624a04a940759856bd3",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "FloatProgress(value=0.0, layout=Layout(width='auto'), style=ProgressStyle(bar_color='black'))"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "bd162500c7f54ee1abb88dfaf3b8d368",
       "version_major": 2,
       "version_minor": 1
      },
      "text/plain": [
       "Map(basemap_style=<CartoBasemap.DarkMatter: 'https://basemaps.cartocdn.com/gl/dark-matter-gl-style/style.json'…"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sql = \"\"\"\n",
    "SELECT * FROM 'https://data.dataforcanada.org/processed/statistics_canada/road_network_files/2021/road_2021.parquet'\n",
    "WHERE csd_name_left in ('Toronto', 'Ottawa') OR csd_name_right in ('Toronto', 'Ottawa');\n",
    "\"\"\"\n",
    "query = con.sql(sql)\n",
    "viz(query, con=con)"
   ]
  }
 ],
 "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.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
