carbonplan / data

data catalogs and utilities
https://carbonplan.org/data
MIT License
16 stars 3 forks source link

TopoJSON #149

Open freeman-lab opened 2 years ago

freeman-lab commented 2 years ago

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 commented 2 years ago

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