Search in sources :

Example 1 with WkbDecoder

use of org.geolatte.geom.codec.WkbDecoder 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 WkbDecoder

use of org.geolatte.geom.codec.WkbDecoder 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 WkbDecoder

use of org.geolatte.geom.codec.WkbDecoder 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 4 with WkbDecoder

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

the class GeoDBWkbType method getValue.

@Override
@Nullable
public Geometry getValue(ResultSet rs, int startIndex) throws SQLException {
    byte[] bytes = rs.getBytes(startIndex);
    if (bytes != null) {
        byte[] wkb;
        if (bytes[0] != 0 && bytes[0] != 1) {
            // decodes EWKB
            wkb = new byte[bytes.length - 32];
            System.arraycopy(bytes, 32, wkb, 0, wkb.length);
        } else {
            wkb = bytes;
        }
        WkbDecoder decoder = Wkb.newDecoder(Wkb.Dialect.POSTGIS_EWKB_1);
        return decoder.decode(ByteBuffer.from(wkb));
    } else {
        return null;
    }
}
Also used : WkbDecoder(org.geolatte.geom.codec.WkbDecoder) Nullable(javax.annotation.Nullable)

Example 5 with WkbDecoder

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

the class MySQLWkbType method getValue.

@Override
@Nullable
public Geometry getValue(ResultSet rs, int startIndex) throws SQLException {
    byte[] bytes = rs.getBytes(startIndex);
    if (bytes != null) {
        byte[] wkb = new byte[bytes.length - 4];
        System.arraycopy(bytes, 4, wkb, 0, wkb.length);
        int srid = bytes[3] << 24 | (bytes[2] & 0xff) << 16 | (bytes[1] & 0xff) << 8 | (bytes[0] & 0xff);
        // TODO make sure srid is set
        WkbDecoder decoder = Wkb.newDecoder(Wkb.Dialect.POSTGIS_EWKB_1);
        return decoder.decode(ByteBuffer.from(wkb));
    } else {
        return null;
    }
}
Also used : WkbDecoder(org.geolatte.geom.codec.WkbDecoder) Nullable(javax.annotation.Nullable)

Aggregations

WkbDecoder (org.geolatte.geom.codec.WkbDecoder)5 ByteBuffer (org.geolatte.geom.ByteBuffer)3 Nullable (javax.annotation.Nullable)2 PGobject (org.postgresql.util.PGobject)1