public class WKBReader
extends java.lang.Object
Geometry
from 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 also partially handles
the Extended WKB format used by PostGIS,
by parsing and storing SRID values.
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
for a formal format specification
Modifier and Type | Field and Description |
---|---|
private CoordinateSequenceFactory |
csFactory |
private ByteOrderDataInStream |
dis |
private GeometryFactory |
factory |
private boolean |
hasSRID |
private int |
inputDimension |
private static java.lang.String |
INVALID_GEOM_TYPE_MSG |
private boolean |
isStrict
true if structurally invalid input should be reported rather than repaired.
|
private double[] |
ordValues |
private PrecisionModel |
precisionModel |
private int |
SRID |
Constructor and Description |
---|
WKBReader() |
WKBReader(GeometryFactory geometryFactory) |
Modifier and Type | Method and Description |
---|---|
static byte[] |
hexToBytes(java.lang.String hex)
Converts a hexadecimal string to a byte array.
|
private static int |
hexToInt(char hex) |
Geometry |
read(byte[] bytes)
Reads a single
Geometry in WKB format from a byte array. |
Geometry |
read(InStream is)
|
private void |
readCoordinate()
Reads a coordinate value with the specified dimensionality.
|
private CoordinateSequence |
readCoordinateSequence(int size) |
private CoordinateSequence |
readCoordinateSequenceLineString(int size) |
private CoordinateSequence |
readCoordinateSequenceRing(int size) |
private Geometry |
readGeometry() |
private GeometryCollection |
readGeometryCollection() |
private LinearRing |
readLinearRing() |
private LineString |
readLineString() |
private MultiLineString |
readMultiLineString() |
private MultiPoint |
readMultiPoint() |
private MultiPolygon |
readMultiPolygon() |
private Point |
readPoint() |
private Polygon |
readPolygon() |
private Geometry |
setSRID(Geometry g,
int SRID)
Sets the SRID, if it was specified in the WKB
|
private static final java.lang.String INVALID_GEOM_TYPE_MSG
private GeometryFactory factory
private CoordinateSequenceFactory csFactory
private PrecisionModel precisionModel
private int inputDimension
private boolean hasSRID
private int SRID
private boolean isStrict
private ByteOrderDataInStream dis
private double[] ordValues
public WKBReader()
public WKBReader(GeometryFactory geometryFactory)
public static byte[] hexToBytes(java.lang.String hex)
hex
- a string containing hex digitsprivate static int hexToInt(char hex)
public Geometry read(byte[] bytes) throws ParseException
Geometry
in WKB format from a byte array.bytes
- the byte array to read fromParseException
- if the WKB is ill-formedpublic Geometry read(InStream is) throws java.io.IOException, ParseException
is
- the stream to read fromjava.io.IOException
- if the underlying stream creates an errorParseException
- if the WKB is ill-formedprivate Geometry readGeometry() throws java.io.IOException, ParseException
java.io.IOException
ParseException
private Geometry setSRID(Geometry g, int SRID)
g
- the geometry to updateprivate Point readPoint() throws java.io.IOException
java.io.IOException
private LineString readLineString() throws java.io.IOException
java.io.IOException
private LinearRing readLinearRing() throws java.io.IOException
java.io.IOException
private Polygon readPolygon() throws java.io.IOException
java.io.IOException
private MultiPoint readMultiPoint() throws java.io.IOException, ParseException
java.io.IOException
ParseException
private MultiLineString readMultiLineString() throws java.io.IOException, ParseException
java.io.IOException
ParseException
private MultiPolygon readMultiPolygon() throws java.io.IOException, ParseException
java.io.IOException
ParseException
private GeometryCollection readGeometryCollection() throws java.io.IOException, ParseException
java.io.IOException
ParseException
private CoordinateSequence readCoordinateSequence(int size) throws java.io.IOException
java.io.IOException
private CoordinateSequence readCoordinateSequenceLineString(int size) throws java.io.IOException
java.io.IOException
private CoordinateSequence readCoordinateSequenceRing(int size) throws java.io.IOException
java.io.IOException
private void readCoordinate() throws java.io.IOException
java.io.IOException