Guest User

Untitled

a guest
Apr 23rd, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. zip2topojson() {
  2. NAME=$(basename $1 .zip)
  3. OUTPUT="$2"
  4.  
  5. unzip -o $NAME.zip -d $NAME
  6.  
  7. cd $NAME/
  8.  
  9. [ -f $NAME.geo.json ] && rm $NAME.geo.json
  10. ogr2ogr -f GeoJSON -s_srs $NAME.prj -t_srs EPSG:4326 $NAME.geo.json $NAME.shp
  11.  
  12. npx -p topojson -c "geo2topo -q 1e6 -o $NAME.topo.json $NAME=$NAME.geo.json"
  13.  
  14. mv $NAME.topo.json $NAME.topo.json__old
  15. cat $NAME.topo.json__old | perl -pe 's/(\{"type":"(Multi)?Polygon")/\n \1/g; s/(\]\}\},"arcs":)/\n\1/g' > $NAME.topo.json
  16. rm $NAME.topo.json__old
  17.  
  18. cd ..
  19.  
  20. mv "$NAME/$NAME.topo.json" "./$OUTPUT"
  21.  
  22. rm -r $NAME/
  23. }
  24.  
  25. ##################################################################
  26. # usage: zip2topojson reg2011_g.zip regions.topo.json
  27. #
  28. # `ogr2ogr` (`$ brew install gdal`), `geo2topo`, `npx`
  29. # zip2topojson reg2011_g.zip regions.topo.json
Add Comment
Please, Sign In to add comment