Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hooobot/district statistics #92

Merged
merged 7 commits into from
Aug 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
/dist
/tmp
/out-tsc
/data-pipeline/district-shapes/*

# Runtime data
pids
Expand Down Expand Up @@ -45,6 +46,10 @@ bower_components
!.vscode/launch.json
!.vscode/extensions.json

# IDE - JupyterNotebooks
.ipynb_checkpoints
*/.ipynb_checkpoints/*

# misc
.sass-cache
connect.lock
Expand Down
2 changes: 1 addition & 1 deletion data-pipeline/CombineJurisdictions.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -814,7 +814,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.4"
"version": "3.11.3"
},
"vscode": {
"interpreter": {
Expand Down
136 changes: 136 additions & 0 deletions data-pipeline/DistrictStatistics.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "9ad655a9-5e0d-4905-a07f-42453777469b",
"metadata": {},
"outputs": [],
"source": [
"\"\"\"\n",
"Calculates percentage of land within house and senate districts\n",
"\n",
"@file: DistrictStatistics.ipynb\n",
"\"\"\""
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "9bfe5c8c-50fe-48e0-9019-4fc7ee0bada3",
"metadata": {},
"outputs": [],
"source": [
"import geopandas as gpd"
]
},
{
"cell_type": "markdown",
"id": "d7a0c367-76c4-492b-a3c7-26fbe79172e5",
"metadata": {},
"source": [
"## Format districts to specified shape files"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "a5c71b5b-45db-42e8-b67c-bab79a6c6016",
"metadata": {},
"outputs": [],
"source": [
"\"\"\"\n",
"Disclaimer - '.dbf' files has a column name limitation of 10 characters\n",
"As .dbf files only contain the attribute data of the .shp files,\n",
"in addition to concerns on renaming every column,\n",
"this program voluntarily ignores the proceeding column warning.\n",
"\"\"\""
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "3951edc6-367a-48e9-a0dc-1c3e315389be",
"metadata": {},
"outputs": [],
"source": [
"# Calculate shape files fore house districts\n",
"\n",
"gdf = gpd.read_file('../data/house-districts.min.geojson')\n",
"gdf.to_file('./district-shapes/house-districts.shp', driver='ESRI Shapefile')"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "cacd5911-6077-4ead-a07c-02bd25467c4b",
"metadata": {},
"outputs": [],
"source": [
"# Calculate shape files fore senate districts\n",
"\n",
"gdf = gpd.read_file('../data/senate-districts.min.geojson')\n",
"gdf.to_file('./district-shapes/senate-districts.shp', driver='ESRI Shapefile')"
]
},
{
"cell_type": "markdown",
"id": "b5da6862-01ab-4afa-a502-06b4da7be3ed",
"metadata": {},
"source": [
"## Define polygon areas within a shapefile"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "e21746f7-b630-47e8-ac6d-0402dbfcd41f",
"metadata": {},
"outputs": [],
"source": [
"# Calculate area for house district\n",
"\n",
"gdf_house = gpd.read_file('./district-shapes/house-districts.shp')\n",
"\n",
"# CRS needed for better area calculation\n",
"gdf_house = gdf_house.to_crs(epsg=3857)\n",
"gdf_house['house_area'] = gdf_house['geometry'].area"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b8d6156a-3476-4f0a-a57d-10a8f1207e9a",
"metadata": {},
"outputs": [],
"source": [
"# Calculate area for senate district\n",
"\n",
"gdf_senate = gpd.read_file('./district-shapes/senate-districts.shp')\n",
"gdf_senate = gdf_senate.to_crs(epsg=3857)\n",
"gdf_senate['senate_area'] = gdf_senate['geometry'].area"
]
}
],
"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.11.3"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Binary file not shown.
9 changes: 8 additions & 1 deletion humans.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,12 @@
Contact: mavenmia92 [at] gmail.com
GitHub: @avenmia

Software Developer: Eric Lam
GitHub : @airyclam

Software Developer: Hubert Liang
Contact: hubertl [at] hawaii.edu
GitHub: @Hooobot

/* SITE */
Last update: 2022/09/20
Last update: 2023/07/30