Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
#!/usr/bin/env bash
# Bulk convert shapefiles to geojson using ogr2ogr
# For more information, see
# 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"
# unzip files and convert all shapefiles
for zipped in "$@"; do
unzip -o "$zipped" -d $FOLDER;
cd "$FOLDER"
for shp in *.shp; do shp2geojson "$CURDIR" ${shp%\.*}; done
rm -r "$FOLDER"
# 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.