Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to simplify with topojson API?

Tags:

topojson

So I have no problem simplifying using topojson from the command line using the -s flag, however, I can't figure out how to do it from the node module.

I see a topojson.simplify() method, but I can't figure out how it works as there is no documentation.

Does anyone have any insight?

like image 635
user3121069 Avatar asked Oct 17 '25 07:10

user3121069


1 Answers

By looking at the simplification tests for topojson, I was able to figure out how to use toposjson.simplify(), but I can't fully claim to know whats going on. You can see the tests on the topojson github.

Basically topojson.simplify takes a topology input and has 2 possible options for simplification, "retain-proportion" and "minimum-area", you can also pass the coordinate system, aka "cartesian" or "spherical", although it can be inferred under most circumstances.

examples:

output = topojson.simplify(topology,{"minimum-area": 2,"coordinate-system": "spherical"});
output =topojson.simplify(topology,{"retain-proportion: 2,"coordinate-system": "spherical"});

I am not really sure exactly what the values you pass into these options mean, however higher values tends to produce more simplification. As a note, retain proportion often returns invalid topologies when passed LineStrings, that may be as intended.

Additionally using the quantization option in topojson.topology can be used to create a smaller, simpler output and may be the best solution to some similar use cases and also doesn't have any clearly documented server API examples anywhere so:

//very simplified, small output
topojson.topology({routes: routesCollection},{"quantization":100});
//very unfiltered, large output
topojson.topology({routes: routesCollection},{"quantization":1e8});

note: the default quantization is 10000 (1e4), so anything less than 10000 will create a smaller output and vice versa.

like image 73
Alex Muro Avatar answered Oct 22 '25 05:10

Alex Muro



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!