Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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
Add Comment
Please, Sign In to add comment