1.1.0 • Published 2 years ago

topobuf v1.1.0

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

Topobuf

Build Status

Topobuf is a compact binary encoding for topographic data.

Topobuf provides lossless^1 compression of TopoJSON data into protocol buffers. Advantages over using JSON-based formats alone:

  • Very compact: typically makes TopoJSON 2-3 times smaller.
  • Smaller even when comparing gzipped sizes: 20-30% for TopoJSON.
  • Can store topology objects too large for JSON.stringify / JSON.parse
  • Can accommodate any TopoJSON data, including extensions with arbitrary properties.

Sample compression sizes

normalgzipped
pa-census-blocks.json280 MB44 MB
pa-census-blocks.pbf114 MB35 MB
us-zips.json15.02 MB3.19 MB
us-zips.pbf4.85 MB2.72 MB
idaho.json1.9 MB612 KB
idaho.pbf567 KB479 KB

Install

npm install topobuf

API

encode

var buffer = topobuf.encode(topojson, new Pbf());

Given a TopoJSON object and a Pbf object to write to, returns a Topobuf as a Buffer object in Node or UInt8Array object in browsers.

decode

var topojson = topobuf.decode(new Pbf(data));

Given a Pbf object with topobuf data, return a TopoJSON object.

See more

This library is based on geobuf by Mapbox, which provides similar functionality for GeoJSON

^1: When using quantized TopoJSON - nearly lossless otherwise