npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

geobuf

v3.0.2

Published

Compact binary encoding for geographic data

Downloads

445,530

Readme

Geobuf

Build Status

Geobuf is a compact binary encoding for geographic data.

Geobuf provides nearly lossless compression of GeoJSON data into protocol buffers. Advantages over using GeoJSON alone:

  • Very compact: typically makes GeoJSON 6-8 times smaller.
  • 2-2.5x smaller even when comparing gzipped sizes.
  • Very fast encoding and decoding — even faster than native JSON parse/stringify.
  • Can accommodate any GeoJSON data, including extensions with arbitrary properties.

The encoding format also potentially allows:

  • Easy incremental parsing — get features out as you read them, without the need to build in-memory representation of the whole data.
  • Partial reads — read only the parts you actually need, skipping the rest.

Think of this as an attempt to design a simple, modern Shapefile successor that works seamlessly with GeoJSON. Unlike Mapbox Vector Tiles, it aims for nearly lossless compression of datasets — without tiling, projecting coordinates, flattening geometries or stripping properties.

Note that the encoding schema is not stable yet — it may still change as we get community feedback and discover new ways to improve it.

"Nearly" lossless means coordinates are encoded with precision of 6 digits after the decimal point (about 10cm).

Sample compression sizes

Data | JSON | JSON (gz) | Geobuf | Geobuf (gz) ------------------- | --------: | --------: | -------: | ----------: US zip codes | 101.85 MB | 26.67 MB | 12.24 MB | 10.48 MB Idaho counties | 10.92 MB | 2.57 MB | 1.37 MB | 1.17 MB

API

encode

var buffer = geobuf.encode(geojson, new Pbf());

Given a GeoJSON object and a Pbf object to write to, returns a Geobuf as UInt8Array array of bytes. In [email protected] or later, you can use Buffer.from to convert back to a buffer.

decode

var geojson = geobuf.decode(new Pbf(data));

Given a Pbf object with Geobuf data, return a GeoJSON object. When loading Geobuf data over XMLHttpRequest, you need to set responseType to arraybuffer.

Install

Node and Browserify:

npm install geobuf

Browser build CDN links:

Building locally:

npm install
npm run build-dev # dist/geobuf-dev.js (development build)
npm run build-min # dist/geobuf.js (minified production build)

Command Line

npm install -g geobuf

Installs these nifty binaries:

  • geobuf2json: turn Geobuf from stdin or specified file to GeoJSON on stdout
  • json2geobuf: turn GeoJSON from stdin or specified file to Geobuf on stdout
  • shp2geobuf: given a Shapefile filename, send Geobuf on stdout
json2geobuf data.json > data.pbf
shp2geobuf myshapefile > data.pbf
geobuf2json data.pbf > data.json

Note that for big files, geobuf2json command can be pretty slow, but the bottleneck is not the decoding, but the native JSON.stringify on the decoded object to pipe it as a string to stdout. On some files, this step may take 40 times more time than actual decoding.

See Also

  • geojsonp — the prototype that led to this project
  • pygeobuf — Python implementation of Geobuf
  • twkb — a geospatial binary encoding that doesn't support topology and doesn't encode any non-geographic properties besides id
  • vector-tile-spec
  • topojson — an extension of GeoJSON that supports topology
  • WKT and WKB — popular in databases
  • EWKB — a popular superset of WKB