Skip to main content

WKT module · geometry writer

TWKBWriter

Encode structured geometry as Tiny Well-Known Binary when a compact binary representation is more useful than readable WKT or general-purpose WKB.

What it writes

Turn structured geometry into transport-sized bytes.

The writer accepts GeoJSON-style geometry, applies the selected dimensional flags, and emits TWKB bytes that can be stored or sent to a service implementing the TWKB specification.

Input

GeoJSON-style point, line, polygon, or collection

Dimensions

XY, XYZ, XYM, or XYZM through writer options

Output

ArrayBuffer containing TWKB

APIs

encode and encodeSync

Detailed guide

TWKBWriter reference

The sections below document installation, usage, dimensional options, and the compact format summary.

From-v4.0

Writer for the Tiny Well-known binary format for representation of geometry.

TWKBWriter
File Extension.wkb,
File TypeBinary
File FormatTiny Well Known Binary
Data FormatGeometry
Supported APIsencode, encodeSync
Encoder TypeSynchronous
Worker Thread✅ Yes

Installation​

npm install @loaders.gl/geospatial
npm install @loaders.gl/core

Usage​

import {TWKBWriter} from '@loaders.gl/geospatial/wkb';
import {encodeSync} from '@loaders.gl/core';

const geometry = {
type: 'Polygon',
coordinates: [
[
[1, 2],
[3, 4],
[5, 6],
[1, 2]
]
]
};
const arrayBuffer = encodeSync(geometry, TWKBWriter, {twkb: {hasZ: false, hasM: false}});

Options​

  • hasZ: Should be true if the GeoJSON input has Z values. These values are expected to be the third coordinate position.
  • hasM: Should be true if the GeoJSON input has M values. Thes are expected to be the third coordinate position if Z values do not exist, or fourth if Z values do exist.

Format Summary​

Well-known binary (TWKB) is a binary geometry encoding to store geometries (it doesn't store attributes). It's used in databases such as PostGIS and as the internal storage format of Shapefiles. It's also being discussed as the internal storage format for a "GeoArrow" specification. TWKB is defined starting on page 62 of the OGC Simple Features specification.

  • Coordinates can be 2-4 dimensions and are interleaved.
  • Positions stored as double precision

image