15

I need to convert a geojson file to topojson and possibly simplify the topojson file. I've managed to install Node.js and the topojson package. But I have no idea how to run topojson.

The wiki lists a bunch of command line options, but where do I run those commands? I've tried running them both in the command prompt and the node shell. Node, GDAL, ogr2ogr and TopoJSON are all new concepts for me, so I'm a bit confused and overwhelmed.

I'm running on Windows by the way.

4 Answers4

31

topojson executable is now changed to geo2topo

  • Installation steps remain the same, just like topojson
  • To create a topo json file from geo json file, geo2topo -o topo-output.json geo-input.json

One way to obtain geo-input.json is from gdal which takes a shape file as input and outputs geojson. gdal can be installed via home brew using brew install gdal

Nitin
  • 7,187
  • 6
  • 31
  • 36
11

this should work fine on windows too

  1. install nodejs http://nodejs.org/
  2. install npm https://npmjs.org/doc/README.html
  3. run npm install -g topojson in your command prompt
  4. use the command prompt to cd to the geojson file
  5. run topojson -o myNewTopojsonFile.json myOldGeojsonFile.json

origin https://gis.stackexchange.com/questions/45138/convert-geojson-to-topojson

Community
  • 1
  • 1
Fresheyeball
  • 29,567
  • 20
  • 102
  • 164
  • 7
    The first 4 steps works fine. But when using the topojson command, I'm prompted with "topojson is not an internal command...etc". –  May 18 '13 at 20:37
  • I actually gave up on Windows and installed Ubuntu on my laptop :) I'm having problems installing gdal now, but at least topojson is working. Thanks for your help, I'll mark this answer as correct since it probably should work for most users. –  May 19 '13 at 11:15
  • I get through a portion of npm install -g topojson, but it fails with lines such as gyp ERR! build error gyp ERR! stack Error: not found: make gyp ERR! stack at F (/usr/local/lib/node_modules/npm/node_modules/which/which.js:43:28) – Marjorie Roswell Dec 07 '13 at 22:30
  • @MarjorieRoswell install gyp – Fresheyeball Dec 07 '13 at 23:07
  • thanks very much Fresheyeball. Went ahead and did that only to continue to get errors. Do I need to add gyp to my path? (it seems to reside in several locations when I do a search for it) I'm still getting that error message, even after doing 'sudo npm install -g gyp' (actually, when I run the topjson command, it complains that d3 is missing, and when I do 'sudo npm install -g d3' I get that gyp error. – Marjorie Roswell Dec 08 '13 at 05:24
  • @MarjorieRoswell yeah, it does sound like a path issue. – Fresheyeball Dec 08 '13 at 19:57
  • Success. I learned that installing Xcode does NOT install Command Line Tools by default. I had to install via Xcode > Preferences > Downloads > Components I had seen the command line tools displayed at: Xcode > Preferences > Locations > Command Line Tools (It said "Command Line Tools" and displayed a path!) But that didn't mean it was installed, apparently. Now installed, I got through 'npm install -g topojson' successfully. – Marjorie Roswell Dec 09 '13 at 00:03
  • @MarjorieRoswell oh yeah. For osx its a requirement to get almost anything done. – Fresheyeball Dec 09 '13 at 16:02
4

I had the same issue on Ubuntu 14.04.

I found that my node.js executable is called nodejs instead of node.

I opened the topojson script (usr/bin/topojson) and found that it was trying to run topojson with a node executable called node.

#!/usr/bin/env node

I edited this file so that it runs with nodejs instead

#!/usr/bin/env nodejs

and now it works fine for me.

Hope this helps someone else.

Henry Steere
  • 186
  • 1
  • 6
1

It has been changed to geo2topo

1) Run

sudo npm install -g geo2topo

2) check if it returns the path

which geo2topo

It should give the path /usr/bin/geo2topo

3) Use it to convert your geojson file

geo2topo -o output.json input.json
Abhishek Chandran
  • 1,536
  • 1
  • 13
  • 21