Last active
January 30, 2018 15:10
-
-
Save JirkaChadima/015b17d3f950b8b48d8ac5d7ee86529e to your computer and use it in GitHub Desktop.
cz-region-boundaries snippets
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 | |
# GPS data passed through https://github.com/tyrasd/osmtogeojson | |
curl -X POST 'https://lz4.overpass-api.de/api/interpreter' -d@overpass-query.txt | osmtogeojson > src.geojson | |
# utility script from https://github.com/JirkaChadima/cz-region-boundaries/blob/master/scripts/prepare-gps-data.js | |
node prepare-gps-data.js | |
# ZIP codes processing | |
PSCSOURCE='https://www.ceskaposta.cz/documents/10180/3738087/xls_pcobc.zip/50617e56-6e9a-4335-9608-96fec214e6ef' | |
# https://github.com/JirkaChadima/cz-region-boundaries/blob/master/data/zip/county-region.csv, collected from https://cs.wikipedia.org/wiki/Okresy_v_%C4%8Cesku#Okresy_podle_samospr%C3%A1vn%C3%BDch_kraj%C5%AF | |
OKRESFILE="../data/zip/county-region.csv" | |
ZIPFILE="src.zip" | |
FILE='zv_pcobc' | |
PSCFILE="../data/zip/zip-county.csv" | |
RESULT="../data/zip/zip-region.csv" | |
wget "$PSCSOURCE" -O src.zip | |
unzip -n "$ZIPFILE" | |
libreoffice --headless --convert-to csv --infilter=csv:44,34,76 "$FILE.xls" --outdir . > /dev/null | |
cut -d, -f2,5 "$FILE.csv" | tail -n +2 | sort | uniq > "$PSCFILE" | |
# This bash magic is basically an Excel contingency table | |
join -t ',' -1 2 -2 1 -o 1.1,2.2 <(sort -t ',' -k2,2 "$PSCFILE") <(sort -t ',' -k1,1 "$OKRESFILE") | sort | uniq > "$RESULT" | |
rm "$ZIPFILE" | |
rm "$FILE.xls" | |
rm "$FILE.csv" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment