Skip to content

Instantly share code, notes, and snippets.

@benbalter
Last active April 23, 2024 13:16
Show Gist options
  • Select an option

  • Save benbalter/5858851 to your computer and use it in GitHub Desktop.

Select an option

Save benbalter/5858851 to your computer and use it in GitHub Desktop.
Bulk convert shapefiles to geojson using ogr2ogr
#geojson conversion
function shp2geojson() {
ogr2ogr -f GeoJSON -t_srs crs:84 "$1.geojson" "$1.shp"
}
#unzip all files in a directory
for var in *.zip; do unzip "$var";done
#convert all shapefiles
for var in *.shp; do shp2geojson ${var%\.*}; done
@chopper26
Copy link

gembel

@planemad
Copy link

Heres a simple one liner if you already have a folder containing all the .shp that you want converted. Just cd into the folder containing the shapefiles and run this:

for filename in ./*.shp; do mkdir -p geojson; ogr2ogr -f "GeoJSON" "./geojson/$filename.geojson" "$filename";done

Install gdal if you get a ogr2ogr command not found error: https://gdal.org/download.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment