-
-
Save reubano/3234a46ad123b2d4e2df to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env bash | |
# Bulk convert shapefiles to geojson using ogr2ogr | |
# For more information, see http://ben.balter.com/2013/06/26/how-to-convert-shapefiles-to-geojson-for-use-on-github/ | |
# | |
# usage: geojsonize *.zip | |
# | |
# Note: Assumes you're in a folder with one or more zip files containing shape files | |
# and Outputs as geojson with the crs:84 SRS (for use on GitHub or elsewhere) | |
# geojson conversion | |
function shp2geojson() { | |
ogr2ogr -f GeoJSON -t_srs crs:84 "$1/$2.geojson" "$2.shp" | |
} | |
CURDIR=`PWD` | |
# unzip files and convert all shapefiles | |
for zipped in "$@"; do | |
FOLDER="/tmp/${zipped%\.*}" | |
unzip -o "$zipped" -d $FOLDER; | |
cd "$FOLDER" | |
for shp in *.shp; do shp2geojson "$CURDIR" ${shp%\.*}; done | |
rm -r "$FOLDER" | |
cd $CURDIR | |
done | |
# You'd probably want to `mv *.geojson [path-to-git-repo]/` at this point | |
# so you could commit the file to GitHub | |
# Happy mapping! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment