Class WKBReader
- java.lang.Object
-
- org.locationtech.jts.io.WKBReader
-
public class WKBReader extends java.lang.ObjectReads aGeometryfrom a byte stream in Well-Known Binary format. Supports use of anInStream, 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
WKBWriteris not changed and still write PostGIS WKB geometries- See Also:
for a formal format specification
-
-
Field Summary
Fields Modifier and Type Field Description private CoordinateSequenceFactorycsFactoryprivate ByteOrderDataInStreamdisprivate GeometryFactoryfactoryprivate booleanhasSRIDprivate intinputDimensionprivate static java.lang.StringINVALID_GEOM_TYPE_MSGprivate booleanisStricttrue if structurally invalid input should be reported rather than repaired.private double[]ordValuesprivate PrecisionModelprecisionModelprivate intSRID
-
Constructor Summary
Constructors Constructor Description WKBReader()WKBReader(GeometryFactory geometryFactory)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static byte[]hexToBytes(java.lang.String hex)Converts a hexadecimal string to a byte array.private static inthexToInt(char hex)Geometryread(byte[] bytes)Reads a singleGeometryin WKB format from a byte array.Geometryread(InStream is)private voidreadCoordinate()Reads a coordinate value with the specified dimensionality.private CoordinateSequencereadCoordinateSequence(int size)private CoordinateSequencereadCoordinateSequenceLineString(int size)private CoordinateSequencereadCoordinateSequenceRing(int size)private GeometryreadGeometry()private GeometryCollectionreadGeometryCollection()private LinearRingreadLinearRing()private LineStringreadLineString()private MultiLineStringreadMultiLineString()private MultiPointreadMultiPoint()private MultiPolygonreadMultiPolygon()private PointreadPoint()private PolygonreadPolygon()private GeometrysetSRID(Geometry g, int SRID)Sets the SRID, if it was specified in the WKB
-
-
-
Field Detail
-
INVALID_GEOM_TYPE_MSG
private static final java.lang.String INVALID_GEOM_TYPE_MSG
- See Also:
- Constant Field Values
-
factory
private GeometryFactory factory
-
csFactory
private CoordinateSequenceFactory csFactory
-
precisionModel
private PrecisionModel precisionModel
-
inputDimension
private int inputDimension
-
hasSRID
private boolean hasSRID
-
SRID
private int SRID
-
isStrict
private boolean isStrict
true if structurally invalid input should be reported rather than repaired. At some point this could be made client-controllable.
-
dis
private ByteOrderDataInStream dis
-
ordValues
private double[] ordValues
-
-
Constructor Detail
-
WKBReader
public WKBReader()
-
WKBReader
public WKBReader(GeometryFactory geometryFactory)
-
-
Method Detail
-
hexToBytes
public static byte[] hexToBytes(java.lang.String hex)
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
public Geometry read(byte[] bytes) throws ParseException
Reads a singleGeometryin 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
public Geometry read(InStream is) throws java.io.IOException, ParseException
- Parameters:
is- the stream to read from- Returns:
- the Geometry read
- Throws:
java.io.IOException- if the underlying stream creates an errorParseException- if the WKB is ill-formed
-
readGeometry
private Geometry readGeometry() throws java.io.IOException, ParseException
- Throws:
java.io.IOExceptionParseException
-
setSRID
private Geometry setSRID(Geometry g, int SRID)
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
private Point readPoint() throws java.io.IOException
- Throws:
java.io.IOException
-
readLineString
private LineString readLineString() throws java.io.IOException
- Throws:
java.io.IOException
-
readLinearRing
private LinearRing readLinearRing() throws java.io.IOException
- Throws:
java.io.IOException
-
readPolygon
private Polygon readPolygon() throws java.io.IOException
- Throws:
java.io.IOException
-
readMultiPoint
private MultiPoint readMultiPoint() throws java.io.IOException, ParseException
- Throws:
java.io.IOExceptionParseException
-
readMultiLineString
private MultiLineString readMultiLineString() throws java.io.IOException, ParseException
- Throws:
java.io.IOExceptionParseException
-
readMultiPolygon
private MultiPolygon readMultiPolygon() throws java.io.IOException, ParseException
- Throws:
java.io.IOExceptionParseException
-
readGeometryCollection
private GeometryCollection readGeometryCollection() throws java.io.IOException, ParseException
- Throws:
java.io.IOExceptionParseException
-
readCoordinateSequence
private CoordinateSequence readCoordinateSequence(int size) throws java.io.IOException
- Throws:
java.io.IOException
-
readCoordinateSequenceLineString
private CoordinateSequence readCoordinateSequenceLineString(int size) throws java.io.IOException
- Throws:
java.io.IOException
-
readCoordinateSequenceRing
private CoordinateSequence readCoordinateSequenceRing(int size) throws java.io.IOException
- Throws:
java.io.IOException
-
readCoordinate
private void readCoordinate() throws java.io.IOExceptionReads a coordinate value with the specified dimensionality. Makes the X and Y ordinates precise according to the precision model in use.- Throws:
java.io.IOException
-
-