Created
March 1, 2018 21:44
-
-
Save MetricMike/a9db14cdd2d636679d4dfe06c950c9c8 to your computer and use it in GitHub Desktop.
Steps for converting Shapefiles to unitedstates.io/districts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
declare -A ordinals=(["01"]="1st" ["02"]="2nd" ["03"]="3rd" ["04"]="4th" ["05"]="5th" ["06"]="6th" ["07"]="7th" ["08"]="8th" ["09"]="9th" ["10"]="10th" ["11"]="11th" ["12"]="12th" ["13"]="13th" ["14"]="14th" ["15"]="15th" ["16"]="16th" ["17"]="17th" ["18"]="18th") | |
for filename in pennsylvania_xa*; do | |
DISTRICT_NUM=$(cat ${filename} | jq -r '.features[0].id | tonumber') | |
DISTRICT_ID=$(cat ${filename} | jq -r '.features[0].id') | |
JSON_CODE="PA-${DISTRICT_ID}" | |
JSON_ORD=${ordinals[$DISTRICT_ID]} | |
JSON_DIST="Pennsylvania ${JSON_ORD}" | |
DISTRICT_DIR="PA-${DISTRICT_NUM}" | |
mkdir -p ${DISTRICT_DIR} | |
jq --arg 'JSON_CODE' "${JSON_CODE}" --arg 'JSON_DIST' "${JSON_DIST}" '.features[0].geometry | {geometry: ., type: "Feature", properties: { Code: $JSON_CODE, District: $JSON_DIST }}' ${filename} > "${DISTRICT_DIR}/shape.geojson" | |
tokml "${DISTRICT_DIR}/shape.geojson" > "${DISTRICT_DIR}/shape.kml" | |
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
requires jq, tokml, mapmaker | |
1) Use mapmaker-gui to verify shape, export to geojson | |
a. I used export options "drop-table id-field=DISTRICT" for PA | |
2) Split the state into districts | |
$ geojsplit -v -l 0 -a 2 -o 2018 pennsylvania.json | |
# the first file is empty | |
$ rm pennsylvania_xaa.geojson | |
3) Convert to unitedstates/districts format and make kml | |
$ ./convert_directory.sh |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment