Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TopoJSON #149

Open
freeman-lab opened this issue Oct 27, 2021 · 1 comment
Open

TopoJSON #149

freeman-lab opened this issue Oct 27, 2021 · 1 comment

Comments

@freeman-lab
Copy link
Member

Leaving some notes here regarding conversions from GeoJSON to TopoJSON, which in a recent real world test reduced file size by 4x with no perceptible change in appearance. This is a huge win when making data to serve over the wire (e.g. in any web application), so we should absolutely figure out how to incorporate it into any of our toolchains that generate GeoJSONs.

Starting with a GeoJSON called shape.json, the specific steps are:

geo2topo shape.json > shape-topo.json
topoquantize 1e5 < shape-topo.json > shape-topo-quantized.json

Via the CLI tools from topojson-server and topojson-client.

Then, in Javascript, we simply replace

json('shape.json').then((data) => {
    // ...do stuff with data
}

with

import { feature } from 'topojson-client'

json('shape-topo-quantized.json').then((topology) => {
    const data = feature(topology, topology.objects.shape)
    // ...do stuff with data
}

And we can use the data exactly as we normally would (including getting access to all properties).

Surely there is a way to do this in Python? Might be cumbersome to rely on these CLI tools, but we should definitely be taking advantage of the reduction in file size.

@freeman-lab
Copy link
Member Author

@jhamman points out we might be able to use this library

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant