Writes a
Geometry into Well-Known Binary format.
Supports use of an
OutStream, which allows easy use
with arbitary byte stream sinks.
The WKB format is specified in the
OGC Simple Features for SQL
specification.
This implementation also supports the Extended WKB
standard. Extended WKB allows writing 3-dimensional coordinates
and including the geometry SRID value.
The presence of 3D coordinates is signified
by setting the high bit of the wkbType word.
The presence of an SRID is signified
by setting the third bit of the wkbType word.
EWKB format is upward compatible with the original SFS WKB format.
Empty Points cannot be represented in WKB; an
IllegalArgumentException will be thrown if one is
written.
The WKB specification does not support representing
LinearRings;
they will be written as
LineStrings.
This class is designed to support reuse of a single instance to read multiple
geometries. This class is not thread-safe; each thread should create its own
instance.
Syntax
The following syntax specification describes the version of Well-Known Binary
supported by JTS.
The specification uses a syntax language similar to that used in
the C language. Bitfields are specified from hi-order to lo-order bits.
byte = 1 byte
uint32 = 32 bit unsigned integer (4 bytes)
double = double precision number (8 bytes)
abstract Point { }
Point2D extends Point {
double x;
double y;
}
Point3D extends Point {
double x;
double y;
double z;
}
LinearRing {
uint32 numPoints;
Point points[numPoints];
}
enum wkbGeometryType {
wkbPoint = 1,
wkbLineString = 2,
wkbPolygon = 3,
wkbMultiPoint = 4,
wkbMultiLineString = 5,
wkbMultiPolygon = 6,
wkbGeometryCollection = 7
}
enum byteOrder {
wkbXDR = 0, // Big Endian
wkbNDR = 1 // Little Endian
}
WKBType {
uint32 wkbGeometryType : 8; // values from enum wkbGeometryType
}
EWKBType {
uint32 is3D : 1; // 0 = 2D, 1 = 3D
uint32 noData1 : 1;
uint32 hasSRID : 1; // 0, no, 1 = yes
uint32 noData2 : 21;
uint32 wkbGeometryType : 8; // values from enum wkbGeometryType
}
abstract WKBGeometry {
byte byteOrder; // values from enum byteOrder
EWKBType wkbType
[ uint32 srid; ] // only if hasSRID = yes
}
WKBPoint extends WKBGeometry {
Point point;
}
WKBLineString extends WKBGeometry {
uint32 numCoords;
Point points[numCoords];
}
WKBPolygon extends WKBGeometry {
uint32 numRings;
LinearRing rings[numRings];
}
WKBMultiPoint extends WKBGeometry {
uint32 numElems;
WKBPoint elems[numElems];
}
WKBMultiLineString extends WKBGeometry {
uint32 numElems;
WKBLineString elems[numElems];
}
wkbMultiPolygon extends WKBGeometry {
uint32 numElems;
WKBPolygon elems[numElems];
}
WKBGeometryCollection extends WKBGeometry {
uint32 numElems;
WKBGeometry elems[numElems];
}