[GIS] Batch conversion of Shapefiles to Topojson

batchogr2ogrtopojson

Can i convert more than one shapefile .shp to topojson. Can this be performed using batch processing?

I can convert shape file to topojson one by one but i have about 6000 files and i don't want to merge them i want them to be separately converted to topojson.

I can also batch process ogr2ogr but don't know how to perform that on topojson. Is there any way i could perform this task using a folder of is there any alternate solution to this problem.

Best Answer

A simple bash script should do the trick. For example, you can paste this into your terminal, assuming you’re in the same directory as your shapefiles:

for shapefile in *.shp; do
  topojson -o `basename -s .shp $shapefile`.json -- $shapefile
done

Alternatively, you can put this code into a script, batch.sh:

#!/bin/bash

for shapefile in *.shp; do
  topojson -o `basename -s .shp $shapefile`.json -- $shapefile
done

Make the script executable using chmod u+x batch.sh, and then run it as ./batch.sh.