Skip to main content

WKT module · geometry writer

WKBWriter

Encode structured geometry as compact Well-Known Binary for database, GIS, Shapefile, and Arrow-oriented data paths.

What it writes

Put geometry into a compact, widely understood encoding.

WKBWriter is the binary counterpart to WKBLoader. It preserves geometry structure while leaving feature attributes and table metadata to the surrounding application.

Input

Structured geometry objects

Output

Binary WKB geometry bytes

Dimensions

Optional Z and M coordinates

APIs

encode and encodeSync

Detailed guide

WKBWriter reference

The sections below document format metadata, installation, usage, dimensional options, and geometry details.

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

WKBWriter
File Extension.wkb,
File TypeBinary
File FormatWell 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 {WKBWriter} 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, WKBWriter, {wkb: {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 (WKB) 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. WKB is defined starting on page 62 of the OGC Simple Features specification.

It's essentially a binary representation of WKT. For common geospatial types including (Multi) Point, Line, and Polygon, there's a 1:1 correspondence between WKT/WKB and GeoJSON. WKT and WKB also support extended geometry types, such as Curve, Surface, and TIN, which don't have a correspondence to GeoJSON.

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

image