Class WKBReader
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
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate CoordinateSequenceFactory
private ByteOrderDataInStream
private GeometryFactory
private boolean
private int
private static final String
private boolean
true if structurally invalid input should be reported rather than repaired.private double[]
private PrecisionModel
private int
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic byte[]
hexToBytes
(String hex) Converts a hexadecimal string to a byte array.private static int
hexToInt
(char hex) read
(byte[] bytes) Reads a singleGeometry
in WKB format from a byte array.private void
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
private GeometryCollection
private LinearRing
private LineString
private MultiLineString
private MultiPoint
private MultiPolygon
private Point
private Polygon
private Geometry
Sets the SRID, if it was specified in the WKB
-
Field Details
-
INVALID_GEOM_TYPE_MSG
- See Also:
-
factory
-
csFactory
-
precisionModel
-
inputDimension
private int inputDimension -
hasSRID
private boolean hasSRID -
SRID
private int SRID -
isStrict
private boolean isStricttrue if structurally invalid input should be reported rather than repaired. At some point this could be made client-controllable. -
dis
-
ordValues
private double[] ordValues
-
-
Constructor Details
-
WKBReader
public WKBReader() -
WKBReader
-
-
Method Details
-
hexToBytes
Converts a hexadecimal string to a byte array. The hexadecimal digit symbols are case-insensitive.- Parameters:
hex
- a string containing hex digits- Returns:
- an array of bytes with the value of the hex string
-
hexToInt
private static int hexToInt(char hex) -
read
Reads a singleGeometry
in WKB format from a byte array.- Parameters:
bytes
- the byte array to read from- Returns:
- the geometry read
- Throws:
ParseException
- if the WKB is ill-formed
-
read
- Parameters:
is
- the stream to read from- Returns:
- the Geometry read
- Throws:
IOException
- if the underlying stream creates an errorParseException
- if the WKB is ill-formed
-
readGeometry
- Throws:
IOException
ParseException
-
setSRID
Sets the SRID, if it was specified in the WKB- Parameters:
g
- the geometry to update- Returns:
- the geometry with an updated SRID value, if required
-
readPoint
- Throws:
IOException
-
readLineString
- Throws:
IOException
-
readLinearRing
- Throws:
IOException
-
readPolygon
- Throws:
IOException
-
readMultiPoint
- Throws:
IOException
ParseException
-
readMultiLineString
- Throws:
IOException
ParseException
-
readMultiPolygon
- Throws:
IOException
ParseException
-
readGeometryCollection
- Throws:
IOException
ParseException
-
readCoordinateSequence
- Throws:
IOException
-
readCoordinateSequenceLineString
- Throws:
IOException
-
readCoordinateSequenceRing
- Throws:
IOException
-
readCoordinate
Reads a coordinate value with the specified dimensionality. Makes the X and Y ordinates precise according to the precision model in use.- Throws:
IOException
-