private static Geometry<?> toGeometry(ByteBuffer buffer) { if ( buffer == null ) { return null; } WkbDecoder decoder = Wkb.newDecoder( Wkb.Dialect.HANA_EWKB ); return decoder.decode( buffer ); }
private static Geometry<?> parseWkt(String pgValue) { final WktDecoder decoder = Wkt.newDecoder( Wkt.Dialect.POSTGIS_EWKT_1 ); return decoder.decode( pgValue ); }
@Override public Geometry fromString(String string) { return Wkt.fromWkt( string ); }
public static byte[] toEWKB(Geometry<?> geometry) { WkbEncoder encoder = Wkb.newEncoder( Wkb.Dialect.HANA_EWKB ); ByteBuffer bytes = encoder.encode( geometry, ByteOrder.NDR ); return bytes.toByteArray(); } }
static GeomEntity createFrom(TestDataElement element, Dialect dialect) throws WktDecodeException { WktDecoder decoder = getWktDecoder( dialect ); Geometry geom = decoder.decode( element.wkt ); GeomEntity result = new GeomEntity(); result.setId( element.id ); result.setGeom( geom ); result.setType( element.type ); return result; }
public static WktDecoder getWktDecoder(Dialect dialect) { WktDecoder decoder = null; if ( dialect instanceof AbstractHANADialect ) { decoder = Wkt.newDecoder( Wkt.Dialect.HANA_EWKT ); } else if ( dialect instanceof DB2SpatialDialect ) { decoder = Wkt.newDecoder( Wkt.Dialect.DB2_WKT ); } else { decoder = Wkt.newDecoder( Wkt.Dialect.POSTGIS_EWKT_1 ); } return decoder; } }
@Test public void testWktWithSrid() throws SQLException { String ewkt = Wkt.toWkt( geom ); testCase( ewkt, geom ); }
@Test public void testWkbNDR() throws SQLException { String wkb = Wkb.toWkb( geom, ByteOrder.NDR ).toString(); testCase( wkb, geom ); }
@Override protected Geometry decode(Object o) { return JTS.to( Wkb.fromWkb( ByteBuffer.from( (byte[]) o ) ) ); } }
private Geometry toGeometry(byte[] bytes) { if ( bytes == null ) { return null; } final ByteBuffer buffer = ByteBuffer.from( bytes ); final WkbDecoder decoder = Wkb.newDecoder( Wkb.Dialect.MYSQL_WKB ); return decoder.decode( buffer ); }
/** * Encode the specified {@code Geometry} into a WKB * * @param geometry The value to encode * * @return A byte-array representing the geometry in WKB. */ public static byte[] to(Geometry geometry) { final WkbEncoder encoder = Wkb.newEncoder( Wkb.Dialect.POSTGIS_EWKB_1 ); final ByteBuffer buffer = encoder.encode( geometry, ByteOrder.NDR ); return ( buffer == null ? null : buffer.toByteArray() ); }
WktDecoder decoder = Wkt.newDecoder(); for ( TestDataElement testDataElement : testData ) { if ( testDataElement.type.equalsIgnoreCase( type ) ) { try { result.put( testDataElement.id, decoder.decode( testDataElement.wkt ) );
public static JtsGeomEntity createFrom(TestDataElement element, Dialect dialect) throws ParseException { WktDecoder decoder = getWktDecoder( dialect ); Geometry geom = JTS.to( decoder.decode( element.wkt ) ); JtsGeomEntity result = new JtsGeomEntity(); result.setId( element.id ); result.setGeom( geom ); result.setType( element.type ); return result; }
@Test public void testWktWithoutSrid() throws SQLException { String wkt = Wkt.toWkt( geom ).split( ";" )[1]; testCase( wkt, geomNoSrid ); }
@Test public void testWkbXDR() throws SQLException { String wkb = Wkb.toWkb( geom, ByteOrder.XDR ).toString(); testCase( wkb, geom ); }
@Override protected Geometry decode(Object bytes) { if ( bytes == null ) { return null; } ByteBuffer buffer = ByteBuffer.from( (byte[]) bytes ); WkbDecoder decoder = Wkb.newDecoder( Wkb.Dialect.MYSQL_WKB ); return JTS.to( decoder.decode( buffer ) ); } }
@Override protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options) throws SQLException { final WkbEncoder encoder = Wkb.newEncoder( Wkb.Dialect.MYSQL_WKB ); final Geometry geometry = getJavaDescriptor().unwrap( value, Geometry.class, options ); final ByteBuffer buffer = encoder.encode( geometry, ByteOrder.NDR ); final byte[] bytes = ( buffer == null ? null : buffer.toByteArray() ); st.setBytes( index, bytes ); }
public static Geometry<?> toGeometry(Object object) { if ( object == null ) { return null; } ByteBuffer buffer = null; if ( object instanceof PGobject ) { String pgValue = ( (PGobject) object ).getValue(); if ( pgValue.startsWith( "00" ) || pgValue.startsWith( "01" ) ) { //we have a WKB because this pgValue starts with the bit-order byte buffer = ByteBuffer.from( pgValue ); final WkbDecoder decoder = Wkb.newDecoder( Wkb.Dialect.POSTGIS_EWKB_1 ); return decoder.decode( buffer ); } else { return parseWkt( pgValue ); } } throw new IllegalStateException( "Received object of type " + object.getClass().getCanonicalName() ); }
@Override protected void doBind(CallableStatement st, X value, String name, WrapperOptions options) throws SQLException { final WkbEncoder encoder = Wkb.newEncoder( Wkb.Dialect.MYSQL_WKB ); final Geometry geometry = getJavaDescriptor().unwrap( value, Geometry.class, options ); final ByteBuffer buffer = encoder.encode( geometry, ByteOrder.NDR ); final byte[] bytes = ( buffer == null ? null : buffer.toByteArray() ); st.setBytes( name, bytes ); } };
private PGobject toPGobject(X value, WrapperOptions options) throws SQLException { final WkbEncoder encoder = Wkb.newEncoder( Wkb.Dialect.POSTGIS_EWKB_1 ); final Geometry geometry = getJavaDescriptor().unwrap( value, Geometry.class, options ); final String hexString = encoder.encode( geometry, ByteOrder.NDR ).toString(); final PGobject obj = new PGobject(); obj.setType( "geometry" ); obj.setValue( hexString ); return obj; }