Domanda

What is the difference between GeoJSON and TopoJSON and when would I use one over the other?

The description of TopoJSON on GitHub implies the TopoJSON files are 80% smaller. So why not just use TopoJSON all the time?

È stato utile?

Soluzione

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.

Altri suggerimenti

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top