All Products
Search
Document Center

PolarDB:WKB

Last Updated:Mar 28, 2026

GanosBase surface models can be represented in Well-Known Binary (WKB) format. WKB ensures data precision and facilitates transmission.

How it works

WKB encodes a GanosBase SFMesh object by extracting its data into a sequence of typed numerical values, then serializing those values in the specified byte order.

Two byte orders are supported:

Byte orderConstantValue
Little EndianNDR (Network Data Representation)1
Big EndianXDR (External Data Representation)0

Numerical types

All field sizes and encodings follow these type definitions. The definitions apply to both NDR and XDR 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 types

GanosBase supports all geometry types from the Open Geospatial Consortium (OGC) Simple Feature model, plus three extended types for surface mesh representation:

  • IndexSurface — indexed vertex surface (type code 22)

  • TriangleStrip — triangle strip surface (type code 20)

  • TriangleFan — triangle fan surface (type code 21)

For details on how these types model 3D geometry, see Data models in surface mesh models.

SRID support

Extended Well-Known Text (EWKT) is an extension of Well-Known Text (WKT) that incorporates Spatial Reference System Identifiers (SRIDs). In WKB structures, fields marked /* if WKBSRIDFLAG */ are present only when an SRID is specified.

Definitions

General definitions

// Basic type definitions
// byte  : 1 byte
// uint8 : 1 byte
// uint16: 2 bytes
// uint32: 32-bit unsigned integer (4 bytes)
// float : single-precision number (4 bytes)
// double: double-precision number (8 bytes)

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
LinearRing {
    uint32 numPoints;
    Point points[numPoints];
}

// Normal vector
NormalPoint {
    float x;
    float y;
    float z;
}

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

// Texture coordinate
TexcoordPoint {
    float x;
    float y;
}

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

// 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; // WKBIntType
    varint values[numInt];
}

Extended geometry types

TriangleStrip

WKBTriangleStrip {
    byte byteOrder;
    static uint32 wkbType = 20;
    /*
    #define WKBZOFFSET  0x80000000
    #define WKBMOFFSET  0x40000000
    #define WKBSRIDFLAG 0x20000000
    */
    uint32 srid; /* if WKBSRIDFLAG */
    uint32 numRings = 1;
    LinearRing ring;
}

TriangleFan

WKBTriangleFan {
    byte byteOrder;
    static uint32 wkbType = 21;
    /*
    #define WKBZOFFSET  0x80000000
    #define WKBMOFFSET  0x40000000
    #define WKBSRIDFLAG 0x20000000
    */
    uint32 srid; /* if WKBSRIDFLAG */
    uint32 numRings = 1;
    LinearRing rings
}

IndexSurface

WKBIndexsurface {
    byte byteOrder;
    static uint32 wkbType = 22;
    /*
    #define WKBZOFFSET  0x80000000
    #define WKBMOFFSET  0x40000000
    #define WKBSRIDFLAG 0x20000000
    */
    uint32 srid; /* if WKBSRIDFLAG */
    LinearRing ring;
    varintArray VertexIndex;
    varintArray VertexNum;
}

GeometryCollection

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


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

Texture

enum wkbTFormat
{
    wkbTFRaw = 0;
    wkbTFJPG = 1;
    wkbTFPNG = 2;
}

enum wkbTType
{
    wkbTTFile  = 1;
    wkbTTDB    = 2;
    wkbTTBytes = 3;
    wkbTTWeb   = 4;
}

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

Material

WKBMaterial {
    byte byteOrder;
    static byte version = 1;
    uint1 type;

    uint4 numTextures;
    WKBTexture textures[numTextures];

    WKBString name;

    WKBString data;
}

MeshGeom

WKBMeshGeom
{
    byte byteOrder;
    uint32 wkbType;

    /*
    #define WKBZOFFSET      0x80000000
    #define WKBMOFFSET      0x40000000
    #define WKBSRIDFLAG     0x20000000
    #define WKBGEOMFLAG     0x04000000
    #define WKBNORMALFLAG   0x02000000
    #define WKBTEXCOORDFLAG 0x01000000
    #define WKBREFFLAG      0x00400000
    #define WKBSOLIDFLAG    0x00200000
    */
    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

WKBMatrix {
    double matrix[12];
}

WKBNode
{
    uint8 flags;
    /*
    #define WKBPRIMITIVEFLAG 0x01u<<0
    #define WKBMATRIXFLAG    0x01u<<2
    #define WKBIDFLAG        0x01u<<3
    */
    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;
    static byte magic = 'M';
    static byte version = 1;
    uint16 flags;

    /*
    #define WKBMESHZFLAG        0x0001u       /* have z */
    #define WKBMESHMFLAG        0x0001u<<1    /* have M */
    #define WKBMESHREFFLAG      0x0001u<<4    /* is ref */
    #define WKBMESHGEOMFLAG     0x0001u<<5    /* have meshgeom */
    #define WKBMESHMESHFLAG     0x0001u<<6    /* have mesh */
    #define WKBMESHTEXTUREFLAG  0x0001u<<7    /* have texture */
    #define WKBMESHMATERIALFLAG 0x0001u<<8    /* have material */
    #define WKBMESHLODFLAG      0x0001u<<9    /* have lod */
    #define WKBMESHSRIDFLAG     0x0001u<<11   /* have srid */
    #define WKBMESHUSERFLAG     0x0001u<<12   /* have user data */
    #define WKBMESHBINFLAG      0x0001u<<13   /* have bin data */
    #define WKBMESHEXFLAG       0x0001u<<14   /* have exflags */
    #define WKBMESHSYSFLAG      0x0001u<<15   /* have system data */
    */

    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 */
}

Type code reference

TypewkbType value
WKBTriangleStrip20
WKBTriangleFan21
WKBIndexsurface22
WKBGeometryCollection7

Flag reference

MeshGeom flags

FlagValueDescription
WKBZOFFSET0x80000000Has Z dimension
WKBMOFFSET0x40000000Has M dimension
WKBSRIDFLAG0x20000000Has SRID
WKBGEOMFLAG0x04000000Has geometry collection
WKBNORMALFLAG0x02000000Has normal vectors
WKBTEXCOORDFLAG0x01000000Has texture coordinates
WKBREFFLAG0x00400000Is a reference (external path)
WKBSOLIDFLAG0x00200000Is a solid

SFMesh flags

FlagValueDescription
WKBMESHZFLAG0x0001uHas Z coordinate
WKBMESHMFLAG0x0001u<<1Has M coordinate
WKBMESHREFFLAG0x0001u<<4Is a reference
WKBMESHGEOMFLAG0x0001u<<5Has MeshGeom
WKBMESHMESHFLAG0x0001u<<6Has sub-meshes
WKBMESHTEXTUREFLAG0x0001u<<7Has textures
WKBMESHMATERIALFLAG0x0001u<<8Has materials
WKBMESHLODFLAG0x0001u<<9Has level of detail
WKBMESHSRIDFLAG0x0001u<<11Has SRID
WKBMESHUSERFLAG0x0001u<<12Has user data
WKBMESHBINFLAG0x0001u<<13Has binary data
WKBMESHEXFLAG0x0001u<<14Has extended flags
WKBMESHSYSFLAG0x0001u<<15Has system data

WKBNode flags

FlagValueDescription
WKBPRIMITIVEFLAG0x01u<<0Node is a primitive
WKBMATRIXFLAG0x01u<<2Has transformation matrix
WKBIDFLAG0x01u<<3Has ID