/** * Create a value for this schema using WKB * @param pointSchema a {@link Schema} instance which represents a point; may not be null * @param wkb the original Well-Known binary representation of the coordinate; may not be null * @param srid the coordinate reference system identifier; null if unset/unknown * @return a {@link Struct} which represents a Connect value for this schema; never null */ public static Struct createValue(Schema geomSchema, byte[] wkb, Integer srid) throws IllegalArgumentException { Struct result = Geometry.createValue(geomSchema, wkb, srid); double[] pt = parseWKBPoint(wkb); result.put(X_FIELD, pt[0]); result.put(Y_FIELD, pt[1]); return result; } }
@Test public void shouldConvertMySqlBytesToPoint() throws Exception { byte[] mysqlBytes = DatatypeConverter.parseHexBinary("000000000101000000e3a59bc420f01b4015a143a69d383240"); //This represents 'POINT(6.9845 18.22115554)' MySqlGeometry geom = MySqlGeometry.fromBytes(mysqlBytes); assertTrue(geom.isPoint()); assertEquals(geom.getSrid(), null); double[] coords = Point.parseWKBPoint(geom.getWkb()); assertEquals(coords[0], 6.9845, 0.0001); assertEquals(coords[1], 18.22115554, 0.0001); }
/** * Create a value for this schema using WKB * @param pointSchema a {@link Schema} instance which represents a point; may not be null * @param wkb the original Well-Known binary representation of the coordinate; may not be null * @param srid the coordinate reference system identifier; null if unset/unknown * @return a {@link Struct} which represents a Connect value for this schema; never null */ public static Struct createValue(Schema geomSchema, byte[] wkb, Integer srid) throws IllegalArgumentException { Struct result = Geometry.createValue(geomSchema, wkb, srid); double[] pt = parseWKBPoint(wkb); result.put(X_FIELD, pt[0]); result.put(Y_FIELD, pt[1]); return result; } }
@Test public void shouldConvertMySqlBytesToPoint() throws Exception { byte[] mysqlBytes = DatatypeConverter.parseHexBinary("000000000101000000e3a59bc420f01b4015a143a69d383240"); //This represents 'POINT(6.9845 18.22115554)' MySqlGeometry geom = MySqlGeometry.fromBytes(mysqlBytes); assertTrue(geom.isPoint()); assertEquals(geom.getSrid(), null); double[] coords = Point.parseWKBPoint(geom.getWkb()); assertEquals(coords[0], 6.9845, 0.0001); assertEquals(coords[1], 18.22115554, 0.0001); }