{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "e3a21b55",
   "metadata": {},
   "source": [
    "# Roads and tracts near the park\n",
    "\n",
    "Downloads the streets around the park from OpenStreetMap (osmnx) and Dallas County's Census tracts (pygris), through the app's open-data downloads."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "96cde64e",
   "metadata": {},
   "outputs": [],
   "source": [
    "import osmnx as ox\n",
    "\n",
    "roads = ox.graph_from_point((32.8696, -96.7707), dist=1500, network_type='drive')\n",
    "print(f'{len(roads.nodes):,} intersections, {len(roads.edges):,} road segments')\n",
    "fig, ax = ox.plot_graph(\n",
    "    roads, node_size=0, edge_color='#333333', bgcolor='white', figsize=(6, 6)\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a38ec789",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pygris\n",
    "\n",
    "tracts = pygris.tracts(state='TX', county='113', year=2022, cb=True)\n",
    "print(f'{len(tracts):,} Dallas County tracts')\n",
    "ax = tracts.plot(figsize=(6, 6), color='#dde6f2', edgecolor='#4a6fa5', linewidth=0.4)\n",
    "ax.set_axis_off()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "fc627115",
   "metadata": {},
   "source": [
    "Any other site is refused, and Python has no network of its own:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3599d6b1",
   "metadata": {},
   "outputs": [],
   "source": [
    "import requests\n",
    "\n",
    "try:\n",
    "    requests.get('https://example.com/', timeout=10)\n",
    "except requests.ConnectionError as error:\n",
    "    print(error)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "name": "python3"
  },
  "language_info": {
   "name": "python"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
