3

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.

3 Answers 3

4

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.

1
  • It worked like this for /R %f in (*.shp) do topojson -o "%~dpnf.topojson" "%f" thanks for your help Commented Oct 30, 2013 at 6:05
2

It's not possible to read and write the TopoJSON format using ogr2ogr:

Starting with OGR 2.0, the GeoJSON driver can read the TopoJSON format

(Source: http://www.gdal.org/ogr/drv_geojson.html)

Instead, you can use the topojson command-line application: https://github.com/mbostock/topojson/wiki An example of its application: http://blog.thematicmapping.org/2013/06/converting-shapefiles-to-topojson.html

1

I edited the code and it worked this way.

for /R %f in (*.shp) do topojson -o "%~dpnf.topojson" "%f"

Thanks

The procedure Included

Install Fw tools Install Node.js Set proxy in fwtools if required using

npm config set proxy http://10.x.x.x:port

Install Python the default path should be c:\python27\python.exe

after that run command set python=%pyhton%;c:\python27\python.exe

Install Visual Studio 2010

npm install -g topojson --python

or if it does not work try

npm install -g topojson --python --msvs_version=2010

If there is some error during installation try installing Install Visual c++ 2005

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.