{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b6e053ec",
   "metadata": {},
   "outputs": [],
   "source": [
    "DATA_FOLDER=/data\n",
    "\n",
    "source ../.env"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7535120d-7e2d-4bc1-8bfc-f8240a8b0902",
   "metadata": {},
   "source": [
    "# Export National Address Register File (2025-07 vintage)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ad20ec9f-53d2-4616-84cf-ea98e7f3e39f",
   "metadata": {},
   "outputs": [],
   "source": [
    "output_folder=\"${DATA_FOLDER}/national_address_register/output/2025-07\"\n",
    "output_file=\"${output_folder}/nar_2025_07.parquet\"\n",
    "echo \"Exporting silver.nar_2025_07 table to ${output_file}\" \n",
    "ogr2ogr \\\n",
    "    -lco COMPRESSION=\"ZSTD\" \\\n",
    "    -lco CREATOR=\"www.dataforcanada.org\" \\\n",
    "    -lco WRITE_COVERING_BBOX=\"YES\" \\\n",
    "    -lco SORT_BY_BBOX=\"YES\" \\\n",
    "    -f Parquet \\\n",
    "    ${output_file} \\\n",
    "    \"PG:host=db dbname=${POSTGRES_DB} user=${POSTGRES_USER} password=${POSTGRES_PASSWORD} port=5432\" \\\n",
    "    \"silver.nar_2025_07\""
   ]
  },
  {
   "cell_type": "markdown",
   "id": "12eca225-3d05-4bb7-95fa-7b9df694f53d",
   "metadata": {},
   "source": [
    "# Export National Address Register File (2024-12 vintage)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "4c5bb532",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Exporting silver.nar_2024_12 table to /data/national_address_register/output/2024-12/nar_2024_12.parquet\n"
     ]
    }
   ],
   "source": [
    "output_folder=\"${DATA_FOLDER}/national_address_register/output/2024-12\"\n",
    "output_file=\"${output_folder}/nar_2024_12.parquet\"\n",
    "echo \"Exporting silver.nar_2024_12 table to ${output_file}\" \n",
    "ogr2ogr \\\n",
    "    -lco COMPRESSION=\"ZSTD\" \\\n",
    "    -lco CREATOR=\"www.dataforcanada.org\" \\\n",
    "    -lco WRITE_COVERING_BBOX=\"YES\" \\\n",
    "    -lco SORT_BY_BBOX=\"YES\" \\\n",
    "    -f Parquet \\\n",
    "    ${output_file} \\\n",
    "    \"PG:host=db dbname=${POSTGRES_DB} user=${POSTGRES_USER} password=${POSTGRES_PASSWORD} port=5432\" \\\n",
    "    \"silver.nar_2024_12\""
   ]
  },
  {
   "cell_type": "markdown",
   "id": "245cd8fb-da36-4476-8e5c-4d3665e901d7",
   "metadata": {},
   "source": [
    "# Export National Address Register File (2024-06 vintage)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f3e2a5b5-9b31-4f82-88da-414bf23ba515",
   "metadata": {},
   "outputs": [],
   "source": [
    "output_folder=\"${DATA_FOLDER}/national_address_register/output/2024-06\"\n",
    "output_file=\"${output_folder}/nar_2024_06.parquet\"\n",
    "echo \"Exporting silver.nar_2024_06 table to ${output_file}\" \n",
    "ogr2ogr \\\n",
    "    -lco COMPRESSION=\"ZSTD\" \\\n",
    "    -lco CREATOR=\"www.dataforcanada.org\" \\\n",
    "    -lco WRITE_COVERING_BBOX=\"YES\" \\\n",
    "    -lco SORT_BY_BBOX=\"YES\" \\\n",
    "    -f Parquet \\\n",
    "    ${output_file} \\\n",
    "    \"PG:host=db dbname=${POSTGRES_DB} user=${POSTGRES_USER} password=${POSTGRES_PASSWORD} port=5432\" \\\n",
    "    \"silver.nar_2024_06\""
   ]
  },
  {
   "cell_type": "markdown",
   "id": "56ef7755-06ef-473c-8a1f-0129f6b1dc28",
   "metadata": {},
   "source": [
    "# Export National Address Register File (2023 vintage)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "97df2904-c18d-4132-bc28-f0f454c48c87",
   "metadata": {},
   "outputs": [],
   "source": [
    "output_folder=\"${DATA_FOLDER}/national_address_register/output/2023\"\n",
    "output_file=\"${output_folder}/nar_2023.parquet\"\n",
    "echo \"Exporting silver.nar_2023 table to ${output_file}\"\n",
    "ogr2ogr \\\n",
    "    -lco COMPRESSION=\"ZSTD\" \\\n",
    "    -lco CREATOR=\"www.dataforcanada.org\" \\\n",
    "    -lco WRITE_COVERING_BBOX=\"YES\" \\\n",
    "    -lco SORT_BY_BBOX=\"YES\" \\\n",
    "    -f Parquet \\\n",
    "    ${output_file} \\\n",
    "    \"PG:host=db dbname=${POSTGRES_DB} user=${POSTGRES_USER} password=${POSTGRES_PASSWORD} port=5432\" \\\n",
    "    \"silver.nar_2023\""
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f1bfd838-19aa-4de7-9ca1-61b1215d7865",
   "metadata": {},
   "source": [
    "# Export National Address Register File (2022 vintage)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d2f1210f-0d9c-45de-a019-a438ff9dfa4a",
   "metadata": {},
   "outputs": [],
   "source": [
    "output_folder=\"${DATA_FOLDER}/national_address_register/output/2022\"\n",
    "output_file=\"${output_folder}/nar_2022.parquet\"\n",
    "echo \"Exporting silver.nar_2022 table to ${output_file}\"\n",
    "ogr2ogr \\\n",
    "    -lco COMPRESSION=\"ZSTD\" \\\n",
    "    -lco CREATOR=\"www.dataforcanada.org\" \\\n",
    "    -lco WRITE_COVERING_BBOX=\"YES\" \\\n",
    "    -lco SORT_BY_BBOX=\"YES\" \\\n",
    "    -f Parquet \\\n",
    "    ${output_file} \\\n",
    "    \"PG:host=db dbname=${POSTGRES_DB} user=${POSTGRES_USER} password=${POSTGRES_PASSWORD} port=5432\" \\\n",
    "    \"silver.nar_2022\""
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Bash",
   "language": "bash",
   "name": "bash"
  },
  "language_info": {
   "codemirror_mode": "shell",
   "file_extension": ".sh",
   "mimetype": "text/x-sh",
   "name": "bash"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
