Skip to content

Instantly share code, notes, and snippets.

@defvol
Forked from benbalter/geojson-conversion.sh
Last active December 24, 2015 01:19
Show Gist options
  • Save defvol/6722511 to your computer and use it in GitHub Desktop.
Save defvol/6722511 to your computer and use it in GitHub Desktop.
# 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/
# Note: Assumes you're in a folder with one or more shape files at most 2 levels deep the file structure
# 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.geojson" "$1.shp"
}
if [ $# -gt 0 ]; then
# Convert all shapefiles in folder
for file in $(find $1 -maxdepth 2 -name "*.shp")
do
shp2geojson ${file%\.*};
done
else
echo "translates shapefiles to geojson"
echo "usage: $0 <directory>"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment