[geos-devel] WKB representation is EWKB, not OGC

Mike Toews mwtoews at gmail.com
Wed Dec 4 12:33:17 PST 2013


It appears that the WKB format used by the WKBReader/Writer is not the
OGC WKB as documented in the API [1,2], but is the PostGIS' EWKB
format [3]. This distinction is not mentioned.

>From what I can tell, these two formats are different when used with
non-2D geometries. For example, take 'POINT Z (1 2 3)'.

  encode(ST_AsBinary(g, 'xdr'), 'hex') as ogc,
  encode(ST_AsEWKB(g, 'xdr'), 'hex') as ewkb
FROM (SELECT 'POINT Z (1 2 3)'::geometry AS g) AS f;

-[ RECORD 1 ]----------------------------------------------------
ogc  | 00000003e93ff000000000000040000000000000004008000000000000
ewkb | 00800000013ff000000000000040000000000000004008000000000000

The geometry type parts of the hex strings are:

ogc: 0x000003e9 or better known as 1001 in base-10
ewkb: 0x80000001, from 1 | 0x80000000

Not to mention the differences of M in OGC (parsed, but ignored by
GEOS), and SRID bit mask in EWKB (supported by GEOS).

The WKBWriter doesn't write OGC WKB, as the documentation appears to
claim[2], and the WKBReader actually cannot parse the OpenGIS WKB,
which is also claimed in the documentation [1].

Attempting to read the OGC WKB example throws:
ParseException: Unknown WKB type 48


[1] http://geos.osgeo.org/doxygen/classgeos_1_1io_1_1WKBReader.html
[2] http://geos.osgeo.org/doxygen/classgeos_1_1io_1_1WKBWriter.html
[3] http://trac.osgeo.org/postgis/browser/trunk/doc/ZMSgeoms.txt

More information about the geos-devel mailing list