# Requires Node.js and NPM
sudo npm install -g topojson
# Install the geojson-cli
sudo npm install -g geojson
The geojson
binary allows for truncating precision but it will only act on TopoJSON documents. So, we first convert our original GeoJSON document (geometry.json
) into TopoJSON and then back into GeoJSON while truncating precision.
# Back-up the GeoJSON document, then convert to TopoJSON
cp geometry.json geometry.json.0
topojson -o geometry.topo.json geometry.json
# We have to remove geometry.json because `geojson` won't overwrite it
rm geometry.json; geojson --precision 5 geometry.topo.json
The topojson
binary allows for simplification of arcs where the tolerance is specified in steradians. Check out the table on this Wikipedia page to get an idea of what tolerance you want. Again, to get a GeoJSON document, we use geojson
to convert the TopoJSON back into GeoJSON.
# Simplify arcs shorter than 10x-9 steradians, a reasonable threshold to start with
topojson --simplify 0.000000001 -o geometry.topo.json geometry.json
# Convert back to a GeoJSON document (optional)
rm geometry.json; geojson geometry.topo.json