GeoJSON 与 TopoJSON 的区别

GeoJSON 和 TopoJSON 之间的区别是什么? 什么时候可以使用一个而不是另一个?

在 GitHub 上描述 TopoJSON意味着 TopoJSON 文件要小80% ,那么为什么不一直使用 TopoJSON 呢?

42380 次浏览

TopoJSON is ideal for tidy features that "snap" to each other, like administrative regions, but doesn't help with more messy or organic data. If your data is simply points, then TopoJSON is no help at all.

It depends on many considerations. Among them are the following:

1) The nature (data model) of the feature or features you'd like to represent 2) Any attributes you'd like to have associated with those features 3) How you'd like these features to behave on the page (static vs dynamic)

However, this is a tough question to answer in the abstract. Regarding some specifics, if you have a contiguous polygon coverage or another situation where features are sharing boundaries, topojson's model allows you to exploit the redundancy and factor that into the model.

Read the documentation, dissect examples (e.g, bl.ocks.org), and then get some data and represent it in both geojson and topojson and create your own visualizations.

If you care about file size or topology, then use TopoJSON. If you don’t care about either, then use GeoJSON for simplicity’s sake.

The primary advantage of TopoJSON is size. By eliminating redundancy and using a more efficent fixed-precision integer encoding of coordinates, TopoJSON files are often an order of magnitude smaller than GeoJSON files. The secondary advantage of TopoJSON files is that encoding the topology has useful applications, such as topology-preserving simplification (similar to MapShaper) and automatic mesh generation (as in the state-state boundaries in this example choropleth).

These advantages come at a cost: a more complex file format. In JavaScript, for example, you’d typically use the TopoJSON client library to convert TopoJSON to GeoJSON for use with standard tools such as d3.geoPath. (In Python, you can use topojson.py.) Also, TopoJSON’s integer format requires quantizing coordinates, which means that it can introduce rounding error if you’re not careful. (See the documentation for topojson -q.)

For server-side manipulation of geometries that does not require topology, then GeoJSON is probably the simpler choice. Otherwise, if you need topology or want to send the geometry over the wire to a client, then use TopoJSON.