private static Geometry<?> toGeometry(ByteBuffer buffer) { if ( buffer == null ) { return null; } WkbDecoder decoder = Wkb.newDecoder( Wkb.Dialect.HANA_EWKB ); return decoder.decode( buffer ); }
public static byte[] toEWKB(Geometry<?> geometry) { WkbEncoder encoder = Wkb.newEncoder( Wkb.Dialect.HANA_EWKB ); ByteBuffer bytes = encoder.encode( geometry, ByteOrder.NDR ); return bytes.toByteArray(); } }
@Override protected Geometry decode(Object o) { return JTS.to( Wkb.fromWkb( ByteBuffer.from( (byte[]) o ) ) ); } }
@Test public void testWkbNDR() throws SQLException { String wkb = Wkb.toWkb( geom, ByteOrder.NDR ).toString(); testCase( wkb, geom ); }
/** * Creates a <code>WkbDecoder</code> for the specified WKB <code>Dialect</code>. * * @param dialect the WKB dialect * @return an <code>WkbDecoder</code> that supports the specified dialect */ public static WkbDecoder newDecoder(Dialect dialect) { Class<? extends WkbDecoder> decoderClass = DECODERS.get(dialect); assert (decoderClass != null) : "A variant declared, but no encoder/decoder registered."; return createInstance(decoderClass); }
@Test public void testWkbXDR() throws SQLException { String wkb = Wkb.toWkb( geom, ByteOrder.XDR ).toString(); testCase( wkb, geom ); }
/** * Creates a <code>WkbDecoder</code> for the default WKB <code>Dialect</code>. * * @return an <code>WkbDecoder</code> that supports the specified dialect */ public static WkbDecoder newDecoder() { Class<? extends WkbDecoder> decoderClass = DECODERS.get(DEFAULT_DIALECT); assert (decoderClass != null) : "A variant declared, but no encoder/decoder registered."; return createInstance(decoderClass); }
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() ); }
/** * Encodes a <code>Geometry</code> into a WKB representation using the NDR (little-endian) byte-order. * * <p>This methods uses the default WKB dialect (Postgis v1.5 EWKB ).</p> * * @param geometry The <code>Geometry</code> to be encoded as WKB. * @return A buffer of bytes that contains the WKB-encoded <code>Geometry</code>. */ public static ByteBuffer toWkb(Geometry geometry) { return toWkb(geometry, ByteOrder.NDR); }
private Object readResolve() throws ObjectStreamException { return Wkb.fromWkb(ByteBuffer.from(this.buffer)); }
/** * Creates a <code>WkbEncoder</code> for the specified WKB <code>Dialect</code>. * * @param dialect the WKB dialect * @return an <code>WkbEncoder</code> that supports the specified dialect */ public static WkbEncoder newEncoder(Dialect dialect) { Class<? extends WkbEncoder> decoderClass = ENCODERS.get(dialect); assert (decoderClass != null) : "A variant declared, but no encoder/decoder registered."; return createInstance(decoderClass); }
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(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 ); }
protected Object writeReplace() throws ObjectStreamException { ByteBuffer buffer = Wkb.toWkb(this); return new SerializationProxy(buffer); }
/** * Creates a <code>WkbEncoder</code> for the default WKB <code>Dialect</code>. * * @return an <code>WkbEncoder</code> that supports the specified dialect */ public static WkbEncoder newEncoder() { Class<? extends WkbEncoder> decoderClass = ENCODERS.get(DEFAULT_DIALECT); assert (decoderClass != null) : "A variant declared, but no encoder/decoder registered."; return createInstance(decoderClass); }
@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(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 ); } };
return JTS.from( (org.locationtech.jts.geom.Geometry) object ); final WkbDecoder decoder = Wkb.newDecoder( Wkb.Dialect.POSTGIS_EWKB_1 ); if ( object instanceof Blob ) { return decoder.decode( toByteBuffer( (Blob) object ) );
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; }