Class WKTConverter


  • public class WKTConverter
    extends Object
    Utility class for converting between WKT (Well-Known Text) and WKB (Well-Known Binary) formats.

    This class uses the JTS (Java Topology Suite) library to provide robust WKT/WKB conversion functionality for geospatial data. JTS is a widely-used, well-tested library that implements the OpenGIS Consortium's Simple Features Specification for SQL.

    • Constructor Detail

      • WKTConverter

        public WKTConverter()
    • Method Detail

      • toWKB

        public static byte[] toWKB​(String wkt)
                            throws DatabricksValidationException
        Converts WKT (Well-Known Text) to WKB (Well-Known Binary) format.

        This implementation uses the JTS library to parse the WKT string into a Geometry object and then converts it to WKB format using the custom OGC-compliant WKB writer.

        Parameters:
        wkt - the WKT string to convert
        Returns:
        the WKB representation as a byte array
        Throws:
        DatabricksValidationException - if the WKT is invalid
      • extractSRIDFromEWKT

        public static int extractSRIDFromEWKT​(String ewkt)
        Extracts the SRID from an EWKT (Extended Well-Known Text) string.

        EWKT format includes SRID prefix: "SRID=4326;POINT(1 2)"

        Parameters:
        ewkt - the EWKT string
        Returns:
        the SRID value, or 0 if no SRID is specified
      • removeSRIDFromEWKT

        public static String removeSRIDFromEWKT​(String ewkt)
        Removes the SRID prefix from an EWKT string to get clean WKT.

        Converts "SRID=4326;POINT(1 2)" to "POINT(1 2)"

        Parameters:
        ewkt - the EWKT string
        Returns:
        the clean WKT string without SRID prefix