Search in sources :

Example 1 with ByteBuffer

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

the class MySQLExpectationsFactory method decode.

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

Example 2 with ByteBuffer

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

the class PGGeometryTypeDescriptor method toGeometry.

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());
}
Also used : ByteBuffer(org.geolatte.geom.ByteBuffer) WkbDecoder(org.geolatte.geom.codec.WkbDecoder) PGobject(org.postgresql.util.PGobject)

Example 3 with ByteBuffer

use of org.geolatte.geom.ByteBuffer 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)

Example 4 with ByteBuffer

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

the class MySQLGeometryTypeDescriptor method toGeometry.

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

Example 5 with ByteBuffer

use of org.geolatte.geom.ByteBuffer 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)

Aggregations

ByteBuffer (org.geolatte.geom.ByteBuffer)8 WkbEncoder (org.geolatte.geom.codec.WkbEncoder)5 WkbDecoder (org.geolatte.geom.codec.WkbDecoder)3 CallableStatement (java.sql.CallableStatement)1 PreparedStatement (java.sql.PreparedStatement)1 Geometry (org.geolatte.geom.Geometry)1 WrapperOptions (org.hibernate.type.descriptor.WrapperOptions)1 BasicBinder (org.hibernate.type.descriptor.sql.BasicBinder)1 PGobject (org.postgresql.util.PGobject)1