Class HexWKBEncoder

Object
HexWKBEncoder

public class HexWKBEncoder extends Object
Utility class for encoding JTS geometries as hexadecimal WKB (Well-Known Binary) strings for use with DuckDB's spatial functions.

This encoder provides locale-independent geometry encoding that avoids issues with decimal separator parsing in different system locales. Instead of using WKT (Well-Known Text) which can be misinterpreted in locales that use comma as decimal separator, this class generates binary WKB data encoded as hexadecimal strings for use with DuckDB's ST_GeomFromHEXEWKB function.

Usage:


 Geometry geom = ...;
 StringBuffer sql = new StringBuffer("ST_GeomFromHEXEWKB('");
 HexWKBEncoder.encode(geom, sql);
 sql.append("')");
 
See Also:
  • Constructor Details

    • HexWKBEncoder

      public HexWKBEncoder()
  • Method Details

    • encode

      public static void encode(Geometry g, Appendable writer) throws IOException
      Encodes a JTS geometry as hexadecimal WKB and appends it to the provided writer.

      LinearRing geometries are automatically converted to LineString since DuckDB doesn't support the LinearRing type.

      Parameters:
      g - the geometry to encode
      writer - the target to append the hexadecimal WKB representation to
      Throws:
      IOException - if there's an error writing to the appendable