Class WKBReader

Hierarchy: Object , WKBReader
public class WKBReader
Reads a Geometryfrom a byte stream in Well-Known Binary format. Supports use of an InStream, which allows easy use with arbitrary byte stream sources.

This class reads the format describe in WKBWriter. It partially handles the Extended WKB format used by PostGIS, by parsing and storing SRID values. Although not defined in the WKB spec, empty points are handled if they are represented as a Point with NaN X and Y ordinates.

The reader repairs structurally-invalid input (specifically, LineStrings and LinearRings which contain too few points have vertices added, and non-closed rings are closed).

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.

As of version 1.15, the reader can read geometries following OGC 06-103r4 speification used by Spatialite/Geopackage.

The difference between PostGIS EWKB format and the new OGC specification is that Z and M coordinates are detected with a bit mask on the higher byte in the former case (0x80 for Z and 0x40 for M) while new OGC specification use specif int ranges for 2D gemetries, Z geometries (2D code+1000), M geometries (2D code+2000) and ZM geometries (2D code+3000).

Note that the WKBWriter is not changed and still write PostGIS WKB geometries

See also:
WKBWriter for a formal format specification
public WKBReader()
public WKBReader(GeometryFactory geometryFactory)
public static byte[] hexToBytes(String hex)
Converts a hexadecimal string to a byte array. The hexadecimal digit symbols are case-insensitive.
Parameters:
hex - hex a string containing hex digits
Returns:
an array of bytes with the value of the hex string
public Geometry read(byte[] bytes)
Reads a single Geometry in WKB format from a byte array.
Parameters:
bytes - bytes the byte array to read from
Returns:
the geometry read
Throws:
ParseException - ParseException if the WKB is ill-formed
public Geometry read(InStream is)
Reads a Geometry in binary WKB format from an InStream.
Parameters:
is - is the stream to read from
Returns:
the Geometry read
Throws:
IOException - IOException if the underlying stream creates an error
ParseException - ParseException if the WKB is ill-formed