All Products
Search
Document Center

PolarDB:WKB

Last Updated:Mar 28, 2026

GanosBase surface models are serialized using the Well-Known Binary (WKB) format — a compact binary encoding that preserves full numeric precision and enables efficient data transmission across platforms.

Byte order

WKB supports two byte orders, specified by the leading byteOrder byte in every structure:

ValueNameAlso known as
0XDR (External Data Representation)Big Endian
1NDR (Network Data Representation)Little Endian

All numeric fields in a structure use the byte order declared by that structure's byteOrder byte.

Primitive types

The following primitive types are used throughout WKB structure definitions. All definitions apply to both XDR and NDR byte orders.

TypeSizeDescription
Uint11 byte (8-bit)Unsigned integer
Byte1 byte (8-bit)Signed integer
Uint162 bytes (16-bit)Unsigned integer
Uint324 bytes (32-bit)Unsigned integer
Float4 bytes (32-bit)Floating-point number (IEEE 754)
Double8 bytes (64-bit)Floating-point number (IEEE 754)

Geometric structures

GanosBase supports all basic geometry types defined in the Open Geospatial Consortium (OGC) Simple Feature model, plus three extended surface mesh types:

TypewkbTypeCategory
WKBPoint, WKBLineString, WKBPolygonStandard OGC valuesOGC standard
WKBMultiPoint, WKBMultiLineString, WKBMultiPolygonStandard OGC valuesOGC standard
WKBGeometryCollection7OGC standard
WKBTriangleStrip20GanosBase extension
WKBTriangleFan21GanosBase extension
WKBIndexsurface22GanosBase extension

For details on how these geometry types are used in surface mesh models, see Data models in surface mesh models.

SRID and EWKT

GanosBase WKB supports embedding a spatial reference system identifier (SRID) in geometry structures by setting WKBSRIDFLAG in the wkbType field. This follows the same principle as Extended Well-Known Text (EWKT), which extends WKT to incorporate SRIDs. When WKBSRIDFLAG is set, the srid field is present in the structure; otherwise it is omitted.

Definitions

General types

// Byte order enum
enum WKBByteOrder {
    wkbXDR = 0, // Big Endian
    wkbNDR = 1  // Little Endian
}

// Point types
Point2D {
    double x;
    double y;
}

Point3D {
    double x;
    double y;
    double z;
}

Point4D {
    double x;
    double y;
    double z;
    double m;
}

Point {
    union {
        Point2D point2d;
        Point3D point3d;
        Point4D point4d;
    }
}

// LinearRing: a closed sequence of points
LinearRing {
    uint32 numPoints;
    Point  points[numPoints];
}

// Normal vector point (single-precision)
NormalPoint {
    float x;
    float y;
    float z;
}

NormalPointArray {
    uint32      numPoints;
    NormalPoint points[numPoints];
}

// Texture coordinate point (single-precision)
TexcoordPoint {
    float x;
    float y;
}

TexcoordPointArray {
    uint32        numPoints;
    TexcoordPoint points[numPoints];
}

// Length-prefixed byte string
String {
    uint32 stringLength;
    byte   string[stringLength];
}

// Variable-length integer
enum IntType {
    Int8  = 1;
    Int16 = 2;
    Int32 = 4;
}

varint {
    union {
        uint8  uint8;
        uint16 uint16;
        uint32 uint32;
    }
}

varintArray {
    uint32 numInt;
    byte   intType; // IntType
    varint values[numInt];
}

Extended geometry types

The following types extend the OGC geometry model for surface mesh representation.

wkbType flag bits (extended types)

The upper bits of wkbType encode optional fields. These flags apply to WKBTriangleStrip, WKBTriangleFan, WKBIndexsurface, and WKBMeshGeom.

Bit maskFlag nameEffect
0x80000000WKBZOFFSETGeometry has Z coordinates
0x40000000WKBMOFFSETGeometry has M coordinates
0x20000000WKBSRIDFLAGsrid field is present
0x04000000WKBGEOMFLAGpatches (WKBGeometryCollection) is present
0x02000000WKBNORMALFLAGNormal point arrays are present
0x01000000WKBTEXCOORDFLAGTexture coordinate arrays are present
0x00400000WKBREFFLAGStructure is a reference (path field present)
0x00200000WKBSOLIDFLAGGeometry is a solid

TriangleStrip

A strip of connected triangles sharing edges. wkbType base value: 20.

WKBTriangleStrip {
    byte   byteOrder;
    uint32 wkbType;    // base 20, upper bits are flags
    uint32 srid;       // present if WKBSRIDFLAG is set
    uint32 numRings;   // always 1
    LinearRing ring;
}

TriangleFan

A fan of triangles sharing a common center vertex. wkbType base value: 21.

WKBTriangleFan {
    byte   byteOrder;
    uint32 wkbType;    // base 21, upper bits are flags
    uint32 srid;       // present if WKBSRIDFLAG is set
    uint32 numRings;   // always 1
    LinearRing rings;
}

IndexSurface

An indexed surface mesh that separates vertex data from face topology. wkbType base value: 22.

WKBIndexsurface {
    byte       byteOrder;
    uint32     wkbType;      // base 22, upper bits are flags
    uint32     srid;         // present if WKBSRIDFLAG is set
    LinearRing ring;         // vertex positions
    varintArray VertexIndex; // face connectivity indices
    varintArray VertexNum;   // vertex count per face
}

GeometryCollection

WKBGeometry is a discriminated union over all supported geometry types. WKBGeometryCollection groups multiple geometries under a single structure with wkbType = 7.

WKBGeometry {
    Union {
        WKBPoint          point;
        WKBLineString     linestring;
        WKBPolygon        polygon;
        WKBMultiPoint     mpoint;
        WKBMultiLineString mlinestring;
        WKBMultiPolygon   mpolygon;
        WKBTriangleStrip  strip;
        WKBTriangleFan    fan;
        WKBIndexsurface   indexsurface;
    }
}

WKBGeometryCollection {
    byte   byte_order;
    uint32 wkbType;        // 7
    uint32 numGeometries;
    WKBGeometry geometries[numGeometries];
}

Texture

A texture stores image data embedded in or referenced by an SFMesh. Version is always 1; compress and wrap are always 0.

enum wkbTFormat {
    wkbTFRaw = 0;  // raw pixel data
    wkbTFJPG = 1;  // JPEG compressed
    wkbTFPNG = 2;  // PNG compressed
}

enum wkbTType {
    wkbTTFile  = 1; // file path reference
    wkbTTDB    = 2; // stored in database
    wkbTTBytes = 3; // inline byte data
    wkbTTWeb   = 4; // URL reference
}

WKBTexture {
    byte   byteOrder;
    byte   version;     // always 1
    byte   compress;    // always 0
    byte   format;      // wkbTFormat
    byte   wrap;        // always 0
    byte   type;        // wkbTType
    byte   depth;       // channel depth: 1, 2, or 4
    uint32 width;
    uint32 height;
    uint32 dataLength;
    byte   data[dataLength];
    String name;
}

Material

A material references one or more textures and carries optional JSON or binary metadata.

WKBMaterial {
    byte       byteOrder;
    byte       version;          // always 1
    uint1      type;
    uint4      numTextures;
    WKBTexture textures[numTextures];
    WKBString  name;
    WKBString  data;
}

Meshgeom

WKBMeshGeom is the primary mesh geometry container. Conditional fields are controlled by the upper bits of wkbType (see wkbType flag bits).

WKBMeshGeom {
    byte   byteOrder;
    uint32 wkbType;

    uint32 srid;                              // if WKBSRIDFLAG
    WKBGeometryCollection patches;            // if WKBGEOMFLAG

    uint32           numNormalPointArray;     // if WKBNORMALFLAG
    NormalPointArray normalPoints[numNormalPointArray]; // if WKBNORMALFLAG

    uint32              numTexcoordPointArray;         // if WKBTEXCOORDFLAG
    TexcoordPointArray  texcoordPoints[numTexcoordPointArray]; // if WKBTEXCOORDFLAG

    String path;                              // if WKBREFFLAG
}

SFMesh

SFMesh is the top-level envelope for a complete 3D surface mesh object. The magic byte is always 'M' and version is always 1.

SFMesh flags (uint16)

The flags field controls which optional sub-structures are present.

BitFlag nameEffect
0x0001WKBMESHZFLAGMesh has Z coordinates
0x0002WKBMESHMFLAGMesh has M coordinates
0x0010WKBMESHREFFLAGMesh is a reference; path is present instead of inline data
0x0020WKBMESHGEOMFLAGmeshgeoms array is present
0x0040WKBMESHMESHFLAGsfmesh sub-mesh array is present
0x0080WKBMESHTEXTUREFLAGtextures array is present
0x0100WKBMESHMATERIALFLAGmaterials array is present
0x0200WKBMESHLODFLAGlod (level of detail) field is present
0x0800WKBMESHSRIDFLAGsrid field is present
0x1000WKBMESHUSERFLAGuserdata string is present
0x2000WKBMESHBINFLAGbindata string is present
0x4000WKBMESHEXFLAGexflags field is present
0x8000WKBMESHSYSFLAGsysdata string is present
WKBMatrix {
    double matrix[12];
}

WKBNode {
    uint8  flags;
    // WKBPRIMITIVEFLAG = 0x01u<<0 — node is a leaf (primitive)
    // WKBMATRIXFLAG    = 0x01u<<2 — transformation matrix is present
    // WKBIDFLAG        = 0x01u<<3 — id field is present
    uint32      primitive;  // if WKBPRIMITIVEFLAG
    varintArray children;   // if not WKBPRIMITIVEFLAG
    WKBMatrix   matrix;     // if WKBMATRIXFLAG
    uint32      id;         // if WKBIDFLAG
}

WKBPrimitive {
    uint8  flags;
    uint8  reserved;
    uint16 materialId;
    uint32 index;
}

SFMesh {
    byte   byteOrder;
    byte   magic;      // always 'M'
    byte   version;    // always 1
    uint16 flags;      // see SFMesh flags table above

    uint32 exflags;    // if WKBMESHEXFLAG

    uint32 srid;       // if WKBMESHSRIDFLAG
    uint16 lod;        // if WKBMESHLODFLAG

    uint32 root;                                   // if not WKBMESHREFFLAG
    uint32 numMeshgeom;                            // if WKBMESHGEOMFLAG
    WKBMeshgeom meshgeoms[numMeshgeom];            // if WKBMESHGEOMFLAG

    uint32    numSFMesh;                           // if WKBMESHMESHFLAG
    WKBSFMesh sfmesh[numSFMesh];                   // if WKBMESHMESHFLAG

    uint32     numTexture;                         // if WKBMESHTEXTUREFLAG
    WKBTexture textures[numTexture];               // if WKBMESHTEXTUREFLAG

    uint32       numNode;                          // if not WKBMESHREFFLAG
    WKBNode      nodes[numNode];                   // if not WKBMESHREFFLAG

    uint32       numPrimitives;                    // if not WKBMESHREFFLAG
    WKBPrimitive primitives[numPrimitives];        // if not WKBMESHREFFLAG

    String path;      // if WKBMESHREFFLAG
    String userdata;  // if WKBMESHUSERFLAG
    String bindata;   // if WKBMESHBINFLAG
    String sysdata;   // if WKBMESHSYSFLAG
}

What's next