WKBWriter class

Writes a {@link Geometry} into Well-Known Binary format. Supports use of an {@link OutStream}, which allows easy use with arbitrary 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 {@link IllegalArgumentException} will be thrown if one is written.

The WKB specification does not support representing {@link LinearRing}s; they will be written as {@link LineString}s.

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 pointsnumPoints; }

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 <b>uint32</b> srid; // only if hasSRID = yes }

WKBPoint extends WKBGeometry { Point point; }

WKBLineString extends WKBGeometry { uint32 numCoords; Point pointsnumCoords; }

WKBPolygon extends WKBGeometry { uint32 numRings; LinearRing ringsnumRings; }

WKBMultiPoint extends WKBGeometry { uint32 numElems; WKBPoint elemsnumElems; }

WKBMultiLineString extends WKBGeometry { uint32 numElems; WKBLineString elemsnumElems; }

wkbMultiPolygon extends WKBGeometry { uint32 numElems; WKBPolygon elemsnumElems; }

WKBGeometryCollection extends WKBGeometry { uint32 numElems; WKBGeometry elemsnumElems; }

@see WKBReader

Constructors

WKBWriter()
Creates a writer that writes {@link Geometry}s with output dimension = 2 and Endian.big byte order
WKBWriter.withDim(int outputDimension)
Creates a writer that writes {@link Geometry}s with the given dimension (2 or 3) for output coordinates and {@link ByteOrderValues#Endian.big} byte order. If the input geometry has a small coordinate dimension, coordinates will be padded with {@link Coordinate#NULL_ORDINATE}.
WKBWriter.withDimOrder(int outputDimension, Endian byteOrder)
Creates a writer that writes {@link Geometry}s with the given dimension (2 or 3) for output coordinates and byte order If the input geometry has a small coordinate dimension, coordinates will be padded with {@link Coordinate#NULL_ORDINATE}.
WKBWriter.withDimOrderSrid(int outputDimension, Endian byteOrder, bool includeSRID)
Creates a writer that writes {@link Geometry}s with the given dimension (2 or 3) for output coordinates and byte order. This constructor also takes a flag to control whether srid information will be written. If the input geometry has a small coordinate dimension, coordinates will be padded with {@link Coordinate#NULL_ORDINATE}.
WKBWriter.withDimSrid(int outputDimension, bool includeSRID)
Creates a writer that writes {@link Geometry}s with the given dimension (2 or 3) for output coordinates and {@link ByteOrderValues#Endian.big} byte order. This constructor also takes a flag to control whether srid information will be written. If the input geometry has a smaller coordinate dimension, coordinates will be padded with {@link Coordinate#NULL_ORDINATE}.

Properties

buf List<int>
getter/setter pair
byteArrayOutStream List<int>
getter/setter pair
byteOrder Endian
getter/setter pair
doSpatialite bool
getter/setter pair
hashCode int
The hash code for this object.
no setterinherited
includeSRID bool
getter/setter pair
outputDimension int
getter/setter pair
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited
write(Geometry geom, {dynamic doSpatialite = false}) List<int>
Writes a {@link Geometry} into a byte array.
writeByteOrder(List<int> os) → void
writeCoordinate(CoordinateSequence seq, int index, List<int> os) → void
writeCoordinateSequence(CoordinateSequence seq, bool writeSize, List<int> os) → void
writeGeometryCollection(int geometryType, GeometryCollection gc, List<int> os) → void
writeGeometryType(int geometryType, Geometry g, List<int> os) → void
writeInt(int intValue, List<int> os) → void
writeLineString(LineString line, List<int> os) → void
writePoint(Point pt, List<int> os) → void
writePolygon(Polygon poly, List<int> os) → void
writeStream(Geometry geom, List<int> os, bool isFirst) → void
Writes a {@link Geometry} to an {@link OutStream}.

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Methods

toHex(List<int> bytes) String
Converts a byte array to a hexadecimal string.