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

Martin Davis mtnclimb at telus.net
Wed Dec 4 20:51:25 PST 2013


The JTS doc for the WKBReader says:

"It also partially handles the Extended WKB format used by PostGIS".

My recollection is that at the time JTS was original developed, the OGC 
SFS spec was at version 1.1 (99-049), and did not specify 3D support for 
WKB.  PostGIS extended the spec to allow this - but when the OGC got 
around to specifying it, it did so in a different way. Hence the 
discrepancy.


On 12/4/2013 12:33 PM, Mike Toews wrote:
> Hi,
>
> 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)'.
>
> SELECT
>    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
>
> -Mike
>
> [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
> _______________________________________________
> geos-devel mailing list
> geos-devel at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/geos-devel
>
>
> -----
> No virus found in this message.
> Checked by AVG - www.avg.com
> Version: 2013.0.3426 / Virus Database: 3657/6891 - Release Date: 12/04/13
>
>



More information about the geos-devel mailing list