Skip to content

TopoJSON #149

@freeman-lab

Description

@freeman-lab

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions