Last active
April 16, 2018 09:23
-
-
Save nkint/7dc95c5d83d97148ba96d4a37eaa7e99 to your computer and use it in GitHub Desktop.
zip2topojson
This file contains hidden or 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
zip2topojson() { | |
NAME=$(basename $1 .zip) | |
OUTPUT="$2" | |
unzip -o $NAME.zip -d $NAME | |
cd $NAME/ | |
[ -f $NAME.geo.json ] && rm $NAME.geo.json | |
ogr2ogr -f GeoJSON -s_srs $NAME.prj -t_srs EPSG:4326 $NAME.geo.json $NAME.shp | |
npx -p topojson -c "geo2topo -q 1e6 -o $NAME.topo.json $NAME=$NAME.geo.json" | |
mv $NAME.topo.json $NAME.topo.json__old | |
cat $NAME.topo.json__old | perl -pe 's/(\{"type":"(Multi)?Polygon")/\n \1/g; s/(\]\}\},"arcs":)/\n\1/g' > $NAME.topo.json | |
rm $NAME.topo.json__old | |
cd .. | |
mv "$NAME/$NAME.topo.json" "./$OUTPUT" | |
rm -r $NAME/ | |
} | |
################################################################## | |
# usage: zip2topojson reg2011_g.zip regions.topo.json | |
# | |
# `ogr2ogr` (`$ brew install gdal`), `geo2topo`, `npx` | |
# zip2topojson reg2011_g.zip regions.topo.json |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment