Skip to content

Instantly share code, notes, and snippets.

@reubano
Forked from benbalter/geojson-conversion.sh
Last active August 29, 2015 14:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save reubano/3234a46ad123b2d4e2df to your computer and use it in GitHub Desktop.
Save reubano/3234a46ad123b2d4e2df to your computer and use it in GitHub Desktop.
#!/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