0

I'm trying to convert all geojson files from a folder into topojson files in another folder.

  • I want the same number of files, same file names.
  • I want to keep the data properties (polygon styles, names, ids, etc)

The command I'm running for one file is working fine :

topojson -o topojson/filename.json geojson/filename.json -p

But to target all files I tried many things like this :

topojson -o topojson/*.json geojson/*.json -p

...but I keep getting this kind of error :

$ topojson -o /topojson/*.json geojson/*.json -p
bounds: 2.2547809 48.8183713 2.412474 48.8994609 (spherical)
pre-quantization: 0.0175m (1.58e-7°) 0.00902m (8.11e-8°)
topology: 111711 arcs, 357075 points
post-quantization: 1.75m (0.0000158°) 0.902m (0.00000811°)
prune: retained 111711 / 111711 arcs (100%)
fs.js:549
  return binding.open(pathModule._makeLong(path), stringToFlags(flags), mode);
                 ^

Error: ENOENT: no such file or directory, open 'C:\projectname\topojson\*.json'
    at Error (native)
    at Object.fs.openSync (fs.js:549:18)
    at Object.fs.writeFileSync (fs.js:1161:15)
    at Object.module.exports [as writeFileSync] (C:\Users\my_username\AppData\Roaming\npm\node_modules\topojson\node_modules\rw\lib\rw\write-file-sync.js:14:8)
    at output (C:\Users\my_username\AppData\Roaming\npm\node_modules\topojson\bin\topojson:313:6)
    at notify (C:\Users\my_username\AppData\Roaming\npm\node_modules\topojson\node_modules\queue-async\queue.js:47:18)
    at Object.q.await (C:\Users\my_username\AppData\Roaming\npm\node_modules\topojson\node_modules\queue-async\queue.js:62:25)
    at Object. (C:\Users\my_username\AppData\Roaming\npm\node_modules\topojson\bin\topojson:201:3)
    at Module._compile (module.js:434:26)
    at Object.Module._extensions..js (module.js:452:10)

It's working when you combine all geojson files into one topojson file but I can't find how to write as many files as found in source folder.

Thanks for your help !

Florian Boudot
  • 995
  • 7
  • 9
  • 1
    I'm going to take a guess here and say topojson doesnt support wildcards, so perhaps what you want do to is build out a super simple bash script that accomplishes the same thing with a loop - please see http://stackoverflow.com/a/14505622/1238737 – snkashis Oct 14 '15 at 19:02

1 Answers1

0

As snkashis guessed in his comment about topojson not supporting wildcards I searched and found nothing in the wiki.

Instead I wrote this bash loop that works fine :

for i in geojson/*.json -maxdepth 1; do
    topojson -o topojson/$i $i -p
done

Though I'm getting an error when finished. But that will be another stackoverflow issue :)

Community
  • 1
  • 1
Florian Boudot
  • 995
  • 7
  • 9