Class JtsBinaryWriter


  • public class JtsBinaryWriter
    extends Object
    Create binary representation of geometries. Currently, only text rep (hexed) implementation is tested. Supports only 2 dimensional geometries. It should be easy to add char[] and CharSequence ByteGetter instances, although the latter one is not compatible with older jdks. I did not implement real unsigned 32-bit integers or emulate them with long, as both java Arrays and Strings currently can have only 2^31-1 elements (bytes), so we cannot even get or build Geometries with more than approx. 2^28 coordinates (8 bytes each).
    Author:
    [email protected]
    • Constructor Detail

      • JtsBinaryWriter

        public JtsBinaryWriter()
    • Method Detail

      • valueSetterForEndian

        public static ValueSetter valueSetterForEndian​(ByteSetter bytes,
                                                       byte endian)
        Get the appropriate ValueGetter for my endianness
        Parameters:
        bytes - The ByteSetter
        endian - The endian to be used
        Returns:
        the appropriate ValueSetter for the specified endian
      • writeHexed

        public String writeHexed​(org.locationtech.jts.geom.Geometry geom,
                                 byte REP)
        Write a hex encoded geometry Currently, geometries with more than 2 dimensions and measures are not cleanly supported, but SRID is honored.
        Parameters:
        geom - The geometry to be written
        REP - The endianness representation to use for writing
        Returns:
        String containing the hex-encoded geometry
      • writeHexed

        public String writeHexed​(org.locationtech.jts.geom.Geometry geom)
      • writeBinary

        public byte[] writeBinary​(org.locationtech.jts.geom.Geometry geom,
                                  byte REP)
        Write a binary encoded geometry. Currently, geometries with more than 2 dimensions and measures are not cleanly supported, but SRID is honored.
        Parameters:
        geom - The geometry to be written
        REP - The endianness representation to use for writing
        Returns:
        byte array containing the encoded geometry
      • writeBinary

        public byte[] writeBinary​(org.locationtech.jts.geom.Geometry geom)
      • writeGeometry

        protected void writeGeometry​(org.locationtech.jts.geom.Geometry geom,
                                     ValueSetter dest)
        Parse a geometry starting at offset.
        Parameters:
        geom - The Geometry to be written
        dest - The ValueSettr to write to
      • getWKBType

        public static int getWKBType​(org.locationtech.jts.geom.Geometry geom)
      • estimateBytes

        protected int estimateBytes​(org.locationtech.jts.geom.Geometry geom)
        Estimate how much bytes a geometry will need in WKB.
        Parameters:
        geom - Geometry to estimate
        Returns:
        number of bytes needed
      • getCoordDim

        public static final int getCoordDim​(org.locationtech.jts.geom.Geometry geom)
      • getCoordSequenceDim

        public static final int getCoordSequenceDim​(org.locationtech.jts.geom.CoordinateSequence coords)