Skip to content

Commit

Permalink
Merge pull request #29 from tonmcg/28-alaska-shapefile
Browse files Browse the repository at this point in the history
used higher resolution Alaska shapefile
  • Loading branch information
tonmcg authored Nov 30, 2020
2 parents de5f8e9 + fcd23ad commit d10293c
Show file tree
Hide file tree
Showing 25 changed files with 4,062 additions and 3,201 deletions.
28 changes: 15 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,14 @@ The result of these commands should output a TopoJSON file that looks like the i

### Alaska

Unlike other states within the United States, Alaska does not administer its presidential elections at the county-level but rather at what Alaskans call House Districts. To show results at the Alaska House District-level, we must download cartographic boundary files from the [Alaska Division of Elections](https://elections.alaska.gov/Core/districtmaps.php) and process each of the 40 house districts separately from the county-level files provided by the Geography Division.
Unlike other states within the United States, Alaska does not administer its presidential elections at the county-level but rather at the lower chamber legislative district, or the House District. To show results at the Alaska House District-level, we must download cartographic boundary files from the same Geography Division [Cartographic Boundary Files](https://www.census.gov/geographies/mapping-files/time-series/geo/cartographic-boundary.html) page and process each of the 40 house districts separately from the county-level files.

- Download and unzip Alaska cartographic boundary files
- Download and unzip Alaska lower chamber legislative district cartographic boundary files

```
curl 'https://www.elections.alaska.gov/doc/info/2013-HD-ProclamationPlan.zip' \
-o 2013-HD-ProclamationPlan.zip
unzip 2013-HD-ProclamationPlan.zip
curl 'https://www2.census.gov/geo/tiger/GENZ2019/shp/cb_2019_02_sldl_500k.zip' \
-o cb_2019_02_sldl_500k.zip
unzip cb_2019_02_sldl_500k.zip
```

We now translate and assign each of these 40 house districts a unique FIPS code defined the following way:
Expand All @@ -91,27 +91,29 @@ For example, the FIPS code attached to election results for Alaska House Distric

Each house district in the shapefile contains a number of properties that describe the district. These properties include a unique identifier, the House District number, and geographic descriptions of the district, among other properties. For our purposes, we want to create properties that will allow us uniquely bind 2020 presidential election results to the Alaska geographic layer.

- Filter out all but the `District_N` property
- Input the Alaska House District shapefile
- Create the following new properties:
- `district_n`: a unique, zero-padded, two-digit Alaska House District number based on the `District_N` property
- `district_n`: a unique, zero-padded, two-digit Alaska House District number based on the `SLDLST` property
- `county_name`: combination of "House District " and `district_n`
- `state_fips`: "02"
- `state_fips`: the state FIPS code given by `STATEFP`
- `state_name`: "Alaska"
- `geoid`: combination of `state_fips`, "9", and `district_n`
- Keep only the `geoid`, `state_fips`, `county_name` properties
- Filter out all other fields
- Simplify the layer using the default algorithm, retaining 2% of removable vertices
- Convert the Shapefile into the Albers USA projection
- Output a TopoJSON file named `alaska_districts.json`

```
mapshaper \
-i 2013ProclamationPlan.shp name=alaska_districts \
-each 'district_n=(District_N.length >= 2 ? District_N : new Array(2 - District_N.length + 1).join("0") + District_N),county_name="House District " + district_n,state_fips="02",state_name="Alaska",geoid=state_fips + "9" + district_n' \
-filter-fields geoid,state_fips,county_name \
-i cb_2019_02_sldl_500k.shp name=alaska_districts \
-each 'district_n=Number(SLDLST).toString().length === 2 ? Number(SLDLST).toString() : new Array(2 - Number(SLDLST).toString().length + 1).join("0") + Number(SLDLST).toString(),county_name="House District " + district_n,state_fips=STATEFP,state_name="Alaska",geoid=state_fips + "9" + district_n' \
-filter-fields 'geoid,state_fips,county_name' \
-simplify 2% \
-proj albersusa \
-o format=topojson alaska_districts.json
```

Given that the result of these commands outputs an Albers projection of Alaska, the TopoJSON file should look like the following image, with Alaska occupying the bottom left corner:
The result of these commands should output a TopoJSON file that looks like the image below:
![alaska_districts](https://raw.githubusercontent.com/tonmcg/US_County_Level_Election_Results_08-20/master/img/alaska_districts.png)

### U.S. Election Results
Expand Down
Binary file removed cartography/2020/2013-HD-ProclamationPlan.zip
Binary file not shown.
Binary file removed cartography/2020/2013ProclamationPlan.dbf
Binary file not shown.
1 change: 0 additions & 1 deletion cartography/2020/2013ProclamationPlan.prj

This file was deleted.

Binary file removed cartography/2020/2013ProclamationPlan.sbn
Binary file not shown.
Binary file removed cartography/2020/2013ProclamationPlan.sbx
Binary file not shown.
Binary file removed cartography/2020/2013ProclamationPlan.shp
Binary file not shown.
Binary file removed cartography/2020/2013ProclamationPlan.shx
Binary file not shown.
2 changes: 1 addition & 1 deletion cartography/2020/alaska_districts.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions cartography/2020/cb_2019_02_sldl_500k.cpg
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
UTF-8
Binary file added cartography/2020/cb_2019_02_sldl_500k.dbf
Binary file not shown.
1 change: 1 addition & 0 deletions cartography/2020/cb_2019_02_sldl_500k.prj
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
GEOGCS["GCS_North_American_1983",DATUM["D_North_American_1983",SPHEROID["GRS_1980",6378137,298.257222101]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]]
Binary file added cartography/2020/cb_2019_02_sldl_500k.shp
Binary file not shown.
Loading

0 comments on commit d10293c

Please # to comment.