{
  "cells": [
    {
      "cell_type": "markdown",
      "id": "city-intro",
      "metadata": {},
      "source": "# City viewports and regional projections\n\nRun All with the updated native development runtime and compatible editor extension. This shared session notebook uses generalized Census 2025 boundary assets and synthetic values. County/place layers cover all 50 states and DC. City municipal polygons do not define metropolitan areas or street maps. Each city has its own output cell.\n\nInstall `usa.co`, `usa.ca`, `usa.ny`, `usa.hi` and `usa.tx` with `aner maps install FILE.anermap` before Run All. The source side `plot` collection supplies every required pack. A custom `ANER_MAPS_DIR` must also be set for the notebook process. Installation and chart rendering use local files.\n"
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "id": "city-imports",
      "metadata": {},
      "outputs": [],
      "source": [
        "// Requires the updated native development runtime with city viewports and aner.geo.\n",
        "// Install packs usa.co, usa.ca, usa.ny, usa.hi and usa.tx before running offline.\n",
        "// Values are synthetic. Boundaries: generalized Census 2025 1:500,000 source.\n",
        "// Run the matching notebook for one bounded output cell per city.\n",
        "import aner.plot\n",
        "import aner.geo\n"
      ]
    },
    {
      "cell_type": "markdown",
      "id": "city-boulder-context",
      "metadata": {},
      "source": "## Boulder city\n\nFocus uses the seven character place GEOID, distinct from Boulder County. A local spherical Lambert azimuthal equal area projection is centered on the viewport.\n"
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "id": "city-boulder",
      "metadata": {},
      "outputs": [],
      "source": [
        "let cityCaption = \"Synthetic index; Census 2025 place boundary. Missing places have no data.\"\n",
        "let boulder = plot.map(\"usa.co.places\", List(\"0807850\"), List(8.0))\n",
        "    .focus(key: \"0807850\", padding: 0.20)\n",
        "    .projection(\"lambert_azimuthal_equal_area\")\n",
        "    .title(\"Boulder city, Colorado\")\n",
        "    .caption(\"Synthetic index; Census 2025 municipal boundary, distinct from Boulder County.\")\n",
        "boulder.show()\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "id": "city-california-data",
      "metadata": {},
      "outputs": [],
      "source": [
        "let california = plot.map(region: \"usa.ca.places\",\n",
        "    keys: List(\"0667000\", \"0644000\", \"0655282\"), values: List(12.0, 18.0, 9.0))\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "id": "city-sf",
      "metadata": {},
      "outputs": [],
      "source": [
        "california.focus(\"0667000\")\n",
        "    .extent(west: -122.56, south: 37.68, east: -122.32, north: 37.84)\n",
        "    .title(\"San Francisco urban extent\")\n",
        "    .caption(\"Synthetic index; Census 2025; urban viewport excludes offshore Farallon parts.\").show()\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "id": "city-la",
      "metadata": {},
      "outputs": [],
      "source": [
        "california.focus(\"0644000\").title(\"Los Angeles\").caption(cityCaption).show()\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "id": "city-palo-alto",
      "metadata": {},
      "outputs": [],
      "source": [
        "california.focus(\"0655282\").title(\"Palo Alto\").caption(cityCaption).show()\n"
      ]
    },
    {
      "cell_type": "markdown",
      "id": "city-extent-context",
      "metadata": {},
      "source": "## Explicit extent\n\nThe same GeoExtent can be reused for repeatable views. Zoom retains the original California chart color range. Missing places remain no data; land outside Census places lies outside this layer.\n"
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "id": "city-bay-extent",
      "metadata": {},
      "outputs": [],
      "source": [
        "// Geographic bounds use longitude/latitude degrees and can be reused across charts.\n",
        "let bayArea = geo.extent(west: -122.65, south: 37.20, east: -121.70, north: 38.15)\n",
        "california.extent(bounds: bayArea).projection(\"auto\")\n",
        "    .title(\"Bay Area places in a fixed geographic extent\").caption(cityCaption).show()\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "id": "city-ny",
      "metadata": {},
      "outputs": [],
      "source": [
        "plot.map(\"usa.ny.places\", List(\"3651000\"), List(11.0))\n",
        "    .focus(\"3651000\").title(\"New York City\").caption(cityCaption).show()\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "id": "city-hi",
      "metadata": {},
      "outputs": [],
      "source": [
        "plot.map(\"usa.hi.places\", List(\"1571550\"), List(7.0))\n",
        "    .focus(\"1571550\").title(\"Urban Honolulu, Hawaii\").caption(cityCaption).show()\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "id": "city-tx",
      "metadata": {},
      "outputs": [],
      "source": [
        "plot.map(\"usa.tx.places\", List(\"4835000\"), List(13.0))\n",
        "    .focus(\"4835000\").title(\"Houston, Texas\").caption(cityCaption).show()\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "id": "city-texas-counties",
      "metadata": {},
      "outputs": [],
      "source": [
        "plot.map(\"usa.tx.counties\", List(\"48201\"), List(13.0))\n",
        "    .projection(\"albers\").title(\"Texas counties: Harris County highlighted\")\n",
        "    .caption(\"Synthetic index; Census 2025 counties. Albers is a spherical display projection.\").show()\n"
      ]
    },
    {
      "cell_type": "markdown",
      "id": "city-position-context",
      "metadata": {},
      "source": "## A checked location is different from a municipal polygon\n\nGeoPosition stores WGS84 longitude/latitude degrees. Its named great circle distance method returns a Quantity in meters using a 6,371,008.8m sphere. Display projection does not transform these source coordinates. Precise ellipsoidal distances, spatial joins, geometry columns, raster fields and street context have separate contracts.\n"
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "id": "city-position",
      "metadata": {},
      "outputs": [],
      "source": [
        "import aner.units\n",
        "let boulderCenter: GeoPosition = geo.position(-105.2705, 40.0150)\n",
        "let paloAltoCenter = geo.position(-122.1430, 37.4419)\n",
        "print(boulderCenter.geojson())\n",
        "print(boulderCenter.great_circle_distance(paloAltoCenter).to(\"km\"))\n"
      ]
    },
    {
      "cell_type": "markdown",
      "id": "city-limits",
      "metadata": {},
      "source": "## Interpretation and reproducibility\n\nAll numeric values here are synthetic. Every state county/place layer uses generalized 2025 Census boundaries. Zoom enlarges the available geometry; it does not recover removed source detail. Albers and Lambert azimuthal equal area use spherical display formulas, not general EPSG transforms. Separate chart color normalization still needs care when comparing statistics. See docs/PLOTTING.md and docs/GEOGRAPHIC_TYPES.md for scientific limits, data contracts and the spatial roadmap.\n"
    }
  ],
  "metadata": {
    "kernelspec": {
      "name": "aner",
      "display_name": "Aner",
      "language": "aner"
    },
    "language_info": {
      "name": "aner",
      "file_extension": ".aner",
      "mimetype": "text/x-aner"
    },
    "aner": {
      "status": "example",
      "execution_mode": "persistent-session"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 5
}
