Search in sources :

Example 1 with WkbEncoder

use of org.geolatte.geom.codec.WkbEncoder in project querydsl by querydsl.

the class GeoDBWkbType method setValue.

@Override
public void setValue(PreparedStatement st, int startIndex, Geometry value) throws SQLException {
    WkbEncoder encoder = Wkb.newEncoder(Wkb.Dialect.POSTGIS_EWKB_1);
    ByteBuffer buffer = encoder.encode(value, byteOrder);
    st.setBytes(startIndex, buffer.toByteArray());
}
Also used : WkbEncoder(org.geolatte.geom.codec.WkbEncoder) ByteBuffer(org.geolatte.geom.ByteBuffer)

Example 2 with WkbEncoder

use of org.geolatte.geom.codec.WkbEncoder in project querydsl by querydsl.

the class MySQLWkbType method setValue.

@Override
public void setValue(PreparedStatement st, int startIndex, Geometry value) throws SQLException {
    WkbEncoder encoder = Wkb.newEncoder(Wkb.Dialect.POSTGIS_EWKB_1);
    ByteBuffer buffer = encoder.encode(value, byteOrder);
    int srid = value.getSRID();
    // prepend srid into first 4 bytes
    byte[] wkb = buffer.toByteArray();
    byte[] bytes = new byte[wkb.length + 4];
    bytes[3] = (byte) ((srid >> 24) & 0xFF);
    bytes[2] = (byte) ((srid >> 16) & 0xFF);
    bytes[1] = (byte) ((srid >> 8) & 0xFF);
    bytes[0] = (byte) (srid & 0xFF);
    System.arraycopy(wkb, 0, bytes, 4, wkb.length);
    st.setBytes(startIndex, bytes);
}
Also used : WkbEncoder(org.geolatte.geom.codec.WkbEncoder) ByteBuffer(org.geolatte.geom.ByteBuffer)

Example 3 with WkbEncoder

use of org.geolatte.geom.codec.WkbEncoder in project querydsl by querydsl.

the class GeometryWkbType method setValue.

@Override
public void setValue(PreparedStatement st, int startIndex, Geometry value) throws SQLException {
    WkbEncoder encoder = Wkb.newEncoder(Wkb.Dialect.POSTGIS_EWKB_1);
    ByteBuffer buffer = encoder.encode(value, byteOrder);
    st.setBytes(startIndex, buffer.toByteArray());
}
Also used : WkbEncoder(org.geolatte.geom.codec.WkbEncoder) ByteBuffer(org.geolatte.geom.ByteBuffer)

Example 4 with WkbEncoder

use of org.geolatte.geom.codec.WkbEncoder in project hibernate-orm by hibernate.

the class PGGeometryTypeDescriptor method getBinder.

@Override
public <X> ValueBinder<X> getBinder(final JavaTypeDescriptor<X> javaTypeDescriptor) {
    return new BasicBinder<X>(javaTypeDescriptor, this) {

        @Override
        protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options) throws SQLException {
            final WkbEncoder encoder = Wkb.newEncoder(Wkb.Dialect.POSTGIS_EWKB_1);
            final Geometry geometry = getJavaDescriptor().unwrap(value, Geometry.class, options);
            final byte[] bytes = encoder.encode(geometry, ByteOrder.NDR).toByteArray();
            st.setBytes(index, bytes);
        }

        @Override
        protected void doBind(CallableStatement st, X value, String name, WrapperOptions options) throws SQLException {
            final WkbEncoder encoder = Wkb.newEncoder(Wkb.Dialect.POSTGIS_EWKB_1);
            final Geometry geometry = getJavaDescriptor().unwrap(value, Geometry.class, options);
            final byte[] bytes = encoder.encode(geometry, ByteOrder.NDR).toByteArray();
            st.setBytes(name, bytes);
        }
    };
}
Also used : Geometry(org.geolatte.geom.Geometry) WkbEncoder(org.geolatte.geom.codec.WkbEncoder) CallableStatement(java.sql.CallableStatement) WrapperOptions(org.hibernate.type.descriptor.WrapperOptions) PreparedStatement(java.sql.PreparedStatement) BasicBinder(org.hibernate.type.descriptor.sql.BasicBinder)

Example 5 with WkbEncoder

use of org.geolatte.geom.codec.WkbEncoder in project hibernate-orm by hibernate.

the class GeoDbWkb method to.

/**
	 * 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());
}
Also used : WkbEncoder(org.geolatte.geom.codec.WkbEncoder) ByteBuffer(org.geolatte.geom.ByteBuffer)

Aggregations

WkbEncoder (org.geolatte.geom.codec.WkbEncoder)6 ByteBuffer (org.geolatte.geom.ByteBuffer)5 CallableStatement (java.sql.CallableStatement)2 PreparedStatement (java.sql.PreparedStatement)2 Geometry (org.geolatte.geom.Geometry)2 WrapperOptions (org.hibernate.type.descriptor.WrapperOptions)2 BasicBinder (org.hibernate.type.descriptor.sql.BasicBinder)2