{ "cells": [ { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "# Republic of Ireland electoral divisions" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import os\n", "from datetime import datetime, timezone\n", "from zipfile import ZipFile\n", "import matplotlib.pyplot as plt\n", "import geopandas as gpd\n", "import pooch" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "URL = (\n", " \"https://opendata.arcgis.com/api/v3/datasets/\"\n", " \"429c839036934413bb740bea190f2596_0/downloads/data?\"\n", " \"format=shp&spatialRefId=2157&where=1%3D1\"\n", ")\n", "\n", "KNOWN_HASH = None\n", "FILE_NAME = \"electoral-divisions-2019.zip\"\n", "SUB_DIR = os.path.join(\"data\", \"boundaries\", \"OSi\")\n", "DATA_FILE = os.path.join(SUB_DIR, FILE_NAME)\n", "os.makedirs(SUB_DIR, exist_ok=True)" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "Downloading data from 'https://opendata.arcgis.com/api/v3/datasets/429c839036934413bb740bea190f2596_0/downloads/data?format=shp&spatialRefId=2157&where=1%3D1' to file '/run/media/nms/Backup/Documents/Git/ClimAg/ClimAg/data/OSi/electoral-divisions-2019.zip'.\n", "SHA256 hash of downloaded file: 6dabe10b8e36b256cc981e6967abf7e80d3caf77a957cf2d3a7a9d0dc24e0a3b\n", "Use this value as the 'known_hash' argument of 'pooch.retrieve' to ensure that the file hasn't changed if it is downloaded again in the future.\n" ] } ], "source": [ "# download data if necessary\n", "if not os.path.isfile(os.path.join(SUB_DIR, FILE_NAME)):\n", " pooch.retrieve(\n", " url=URL, known_hash=KNOWN_HASH, fname=FILE_NAME, path=SUB_DIR\n", " )\n", "\n", " with open(\n", " os.path.join(SUB_DIR, f\"{FILE_NAME[:-4]}.txt\"), \"w\", encoding=\"utf-8\"\n", " ) as outfile:\n", " outfile.write(\n", " f\"Data downloaded on: {datetime.now(tz=timezone.utc)}\\n\"\n", " f\"Download URL: {URL}\"\n", " )" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['Electoral_Divisions_-_OSi_National_Statutory_Boundaries_-_2019.shp',\n", " 'Electoral_Divisions_-_OSi_National_Statutory_Boundaries_-_2019.shx',\n", " 'Electoral_Divisions_-_OSi_National_Statutory_Boundaries_-_2019.dbf',\n", " 'Electoral_Divisions_-_OSi_National_Statutory_Boundaries_-_2019.cpg',\n", " 'Electoral_Divisions_-_OSi_National_Statutory_Boundaries_-_2019.prj',\n", " 'Electoral_Divisions_-_OSi_National_Statutory_Boundaries_-_2019.xml']" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ZipFile(DATA_FILE).namelist()" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "data = gpd.read_file(\n", " f\"zip://{DATA_FILE}!\"\n", " \"Electoral_Divisions_-_OSi_National_Statutory_Boundaries_-_2019.shp\"\n", ")" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
| \n", " | ED_ID | \n", "ENGLISH | \n", "GAEILGE | \n", "CONTAE | \n", "COUNTY | \n", "PROVINCE | \n", "GUID | \n", "CENTROID_X | \n", "CENTROID_Y | \n", "AREA | \n", "ESRI_OID | \n", "Shape__Are | \n", "Shape__Len | \n", "geometry | \n", "
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | \n", "267160 | \n", "TURNAPIN | \n", "Turnapain | \n", "Baile Átha Cliath | \n", "DUBLIN | \n", "Leinster | \n", "2ae19629-1cea-13a3-e055-000000000001 | \n", "717365.57 | \n", "740807.88 | \n", "943505.13 | \n", "1 | \n", "9.435051e+05 | \n", "4732.251966 | \n", "POLYGON ((717716.712 741601.510, 717759.461 74... | \n", "
| 1 | \n", "27045 | \n", "DRUMLUMMAN | \n", "Droim Lomáin | \n", "An Cabhán | \n", "CAVAN | \n", "Ulster | \n", "2ae19629-1caa-13a3-e055-000000000001 | \n", "638130.82 | \n", "789588.69 | \n", "17617760.82 | \n", "2 | \n", "1.761776e+07 | \n", "21762.101454 | \n", "POLYGON ((637756.185 787640.988, 637753.646 78... | \n", "
| 2 | \n", "117019 | \n", "CASTLEFORE | \n", "Baile Choille Fóir | \n", "Liatroim | \n", "LEITRIM | \n", "Connacht | \n", "2ae19629-171c-13a3-e055-000000000001 | \n", "606853.02 | \n", "809670.32 | \n", "14080012.63 | \n", "3 | \n", "1.408001e+07 | \n", "21907.071044 | \n", "POLYGON ((608196.069 807618.950, 608244.536 80... | \n", "
| 3 | \n", "37135 | \n", "RAHONA | \n", "Ráth Úna | \n", "An Clár | \n", "CLARE | \n", "Munster | \n", "2ae19629-1fec-13a3-e055-000000000001 | \n", "481634.87 | \n", "649839.86 | \n", "24664562.56 | \n", "4 | \n", "2.466456e+07 | \n", "35830.867808 | \n", "POLYGON ((484212.068 651795.629, 484231.866 65... | \n", "
| 4 | \n", "167021 | \n", "CROSSAKEEL | \n", "Crosa Caoil | \n", "An Mhí | \n", "MEATH | \n", "Leinster | \n", "2ae19629-1861-13a3-e055-000000000001 | \n", "662161.01 | \n", "774125.96 | \n", "20159197.51 | \n", "5 | \n", "2.015920e+07 | \n", "34415.329703 | \n", "POLYGON ((663308.409 776111.796, 663305.294 77... | \n", "