43

How can GeoJSON data to TopoJSON be converted?

TopoJSON files are often smaller than GeoJSON and the conversion allows you to incrementally simplify a dataset, if you wish.

Taras
  • 32,823
  • 4
  • 66
  • 137
Jeff
  • 997
  • 1
  • 7
  • 10
  • Step 3: Convert the data: topojson -o output_file.json input_file.json not working!!!!!!!!!!!! –  Sep 06 '13 at 17:00
  • 1
    topojson -o output_file.json input_file.json works for me under 1.1.0 and 1.4.0. Perhaps you can ask a formal question on here with more info on the problem you're having? Cheers! – Jeff Sep 06 '13 at 18:09

4 Answers4

32

Glad you asked, oh handsome OP.

Install topojson

From the command line (Mac OSX 10.8, assumes homebrew installed):

brew install node.js
npm install -g topojson

Convert The Data

topojson -o output.json input.json
Glorfindel
  • 1,096
  • 2
  • 9
  • 14
Jeff
  • 997
  • 1
  • 7
  • 10
10

The function to create a topojson from a geojson in topojson has been moved to geo2topo

npm install topojson-server -g
geo2topo input.geojson > output.topojson
ow3n
  • 221
  • 2
  • 5
  • For me this does not work. I am getting a not recognized error when trying to run geo2topo after running npm install topojson-server – JoeBe Jan 31 '20 at 02:34
  • Updated the answer to include the global flag -g try it now @JoeBe – ow3n Jan 31 '20 at 16:35
  • thanks. This worked perfectly. It would be great if you could tell me what the difference is here? Why do I need a global flag for this whereas for other libraries I installed until now this was not necessary? What happens behind the hood? – JoeBe Feb 10 '20 at 01:51
  • 1
    Install globally if you are using a package as a command line tool and locally if it only needs to be accessible from scripts in an app https://stackoverflow.com/a/8951576/441878 – ow3n Feb 10 '20 at 11:25
3

I ported the TopoJSON code from JavaScript to Python, following the exact same format Mike uses in his library (along with his +300 tests).

If you feel better with Python, just install the library by running:

pip install pytopojson

And then run:

python geo2topo.py geojson_file

You can also use a quantization parameter. Just use the -h argument to see how it works.

Let me know if this was helpful to you!

fferrin
  • 157
  • 2
0

I have found pretty good online tool for simplifying geospatial data (including GeoJSON) and export to various formats (including TopoJSON) at https://geoprocessing.online/tool/simplify-polygons/. You can upload the GeoJSON, set simplification level and export to TopoJSON. For more information on data size reduction, see this article: https://kb.geoczech.org/knowledge-base/how-to-reduce-size-of-vector-data/

Tonny
  • 555
  • 4
  • 8