Class WKBReader


  • public class WKBReader
    extends Object
    Reads a Geometryfrom a byte stream in Postgis Extended 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 and SQLServer, by parsing and storing SRID values and supporting . 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.

    See Also:
    for a formal format specification
    • 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​(String hex)
      Converts a hexadecimal string to a byte array.
      Geometry read​(byte[] bytes)
      Reads a single Geometry in WKB format from a byte array.
      Geometry read​(InStream is)
      Reads a Geometry in binary WKB format from an InStream.
      protected Polygon readCurvePolygon()  
      protected Geometry readGeometry()  
      protected Geometry readGeometry​(int geometryType)  
      protected Polygon readPolygon()  
      • Methods inherited from class Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • WKBReader

        public WKBReader()
      • WKBReader

        public WKBReader​(GeometryFactory geometryFactory)
    • Method Detail

      • hexToBytes

        public static byte[] hexToBytes​(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
      • read

        public Geometry read​(byte[] bytes)
                      throws ParseException
        Reads a single Geometry 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

        public Geometry read​(InStream is)
                      throws IOException,
                             ParseException
        Reads a Geometry in binary WKB format from an InStream.
        Parameters:
        is - the stream to read from
        Returns:
        the Geometry read
        Throws:
        IOException - if the underlying stream creates an error
        ParseException - if the WKB is ill-formed
      • readGeometry

        protected Geometry readGeometry()
                                 throws IOException,
                                        ParseException
        Throws:
        IOException
        ParseException
      • readGeometry

        protected Geometry readGeometry​(int geometryType)
                                 throws IOException,
                                        ParseException
        Throws:
        IOException
        ParseException
      • readPolygon

        protected Polygon readPolygon()
                               throws IOException,
                                      ParseException
        Throws:
        IOException
        ParseException
      • readCurvePolygon

        protected Polygon readCurvePolygon()
                                    throws IOException,
                                           ParseException
        Throws:
        IOException
        ParseException