Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/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
You can’t perform that action at this time.