Skip to content

Instantly share code, notes, and snippets.

@johnniehard
Created September 1, 2017 05:14
Show Gist options
  • Save johnniehard/dfdc0f95941c58356d48893126c61bb7 to your computer and use it in GitHub Desktop.
Save johnniehard/dfdc0f95941c58356d48893126c61bb7 to your computer and use it in GitHub Desktop.
Converts all shapefiles in input directory to EPSG:4326 GeoJSON files inside of target directory
#!/bin/bash
# Johnnie Hård
# https://synvinkel.org
geojson=".geojson"
# These are set by calling the script with arguments e.g:
# ./shpfolder2geojson.sh MyShapefileDirectory MyGeojsonDirectory
inputdirectory=$1
outputdirectory=$2
mkdir -p
for shapefile in ./$inputdirectory/*.shp; do
file=$(basename $shapefile)
name=${file%.*}
targetpath="./${outputdirectory}/"
echo "converting $file into $name$geojson"
ogr2ogr -f GeoJSON $targetpath$name$geojson -t_srs EPSG:4326 $shapefile
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment