Skip to main content

Geometry binary format

Carry geometry without paying for readable text.

Well-Known Binary (WKB) is the compact binary counterpart to WKT. Its header identifies byte order and geometry type before the coordinate records, making it useful for storage and transport in GIS pipelines.

loaders.gl support​

TypeAPI
LoaderWKBLoader
LoaderHexWKBLoader
WriterWKBWriter

The WKB record path

Read byte order. Identify the geometry. Decode its coordinate records.

WKB keeps geometry compact while retaining the type and dimensionality needed to reconstruct points, lines, polygons, and collections. Spatial reference metadata is a separate concern.

Header

Byte order and 32-bit geometry type

Shape

Point, line, polygon, multiparts, and collections

Dimensions

XY, XYZ, XYM, and XYZM variants

Alternative

WKT for readable text; GeoJSON for JSON APIs

Well-Known Binary (WKB) is a binary version of Well-known Text

Detailed guide

WKB layout and compatibility details

The reference below covers byte order, geometry type codes, dimensional variants, supported shapes, alternatives, and loader support.

Overview​

Well-known binary (WKB) representations are typically shown in hexadecimal strings.

Variations​

  • EKWB - Adds spatial reference systems
  • TWKB

Alternatives​

  • WKT
  • GeoJSON Geometry
  • GML Geometry
FormatSupportDescription
WKB✕
TWKB✕WKB variant reduces binary size ~2x.

TWKB uses varints, precision truncation and zigzag point encoding to reduce binary size ~2x (however compressed size reduction is less)

Version context​

The core WKB geometry layout is defined by the OGC Simple Feature Access family of standards and is also widely implemented by spatial databases such as PostGIS. Extended type codes add Z, M, and CRS dimensions without changing the basic byte-order and geometry-record structure. The loaders.gl WKB path focuses on the core point, line, polygon, multipart, and collection types listed in the support table below.

Ecosystem Support​

  • PostGIS offers a function to return geometries in TWKB format: ST_AsTWKB.

Format Details​

The first byte indicates the byte order for the data:

  • 00 : big endian
  • 01 : little endian

The next 4 bytes are a 32-bit unsigned integer for the geometry type, as described below:

TypeSupported2DZMZM
Geometry✅0000100020003000
Point✅0001100120013001
LineString✅0002100220023002
Polygon✅0003100320033003
MultiPoint✅0004100420043004
MultiLineString✅0005100520053005
MultiPolygon✅0006100620063006
GeometryCollection✅ *0007100720073007
CircularString✕0008100820083008
CompoundCurve✕0009100920093009
CurvePolygon✕0010101020103010
MultiCurve✕0011101120113011
MultiSurface✕0012101220123012
Curve✕0013101320133013
Surface✕0014101420143014
PolyhedralSurface✕0015101520153015
TIN✕0016101620163016
Triangle✕0017101720173017
Circle✕0018101820183018
GeodesicString✕0019101920193019
EllipticalCurve✕0020102020203020
NurbsCurve✕0021102120213021
Clothoid✕0022102220223022
SpiralCurve✕0023102320233023
CompoundSurface✕0024102420243024
BrepSolid✕1025
AffinePlacement✕1021102

Remarks:

  • Many implementations, including loaders.gl, only handle the core GeoJSON geometry equivalents (points, line strings, polygons and to a varying degrees geometry collections of the same).
  • GeometryCollection can be difficult for some clients to handle.