Java Code Examples for io.debezium.data.geometry.Geography

Following code examples demonstrate how to use io.debezium.data.geometry.Geographyfrom debezium. These examples are extracted from various highly rated open source projects. You can directly use these code snippets or view their entire linked source code. These snippets are extracted to provide contextual information about how to use this class in the real world. These samples also let you understand some good practices on how to use io.debezium.data.geometry.Geographyand various code implementation of this class.

    protected Object convertGeography(Column column, Field fieldDefn, Object data) {
        final PostgisGeometry empty = PostgisGeometry.createEmpty();
        return convertValue(column, fieldDefn, data, io.debezium.data.geometry.Geography.createValue(fieldDefn.schema(), empty.getWkb(), empty.getSrid()), (r) -> {
            final Schema schema = fieldDefn.schema();
            try {
                if (data instanceof byte[]) {
                    PostgisGeometry geom = PostgisGeometry.fromHexEwkb(new String((byte[])data, "ASCII"));
                    r.deliver(io.debezium.data.geometry.Geography.createValue(schema, geom.getWkb(), geom.getSrid()));
                }
                else if (data instanceof PGobject) {
                    PGobject pgo = (PGobject)data;
                    PostgisGeometry geom = PostgisGeometry.fromHexEwkb(pgo.getValue());
                    r.deliver(io.debezium.data.geometry.Geography.createValue(schema, geom.getWkb(), geom.getSrid()));
                }
                else if (data instanceof String) {
                    PostgisGeometry geom = PostgisGeometry.fromHexEwkb((String)data);
                    r.deliver(io.debezium.data.geometry.Geography.createValue(schema, geom.getWkb(), geom.getSrid()));
                }
            } catch (IllegalArgumentException | UnsupportedEncodingException e) {
                logger.warn("Error converting to a Geography type", column);
            }
        });
    } 


Advertisement
Javadoc
A semantic type for a Geography class. Used to describe geometries operating on a spherical base (ra

ther than Geometry which operates on a planar basis). This is extremely similar to a Geometry – but they're quite different types and not in a hierarchy.

See the Open Geospatial Consortium Simple Features Access specification for details on the Well-Known-Binary format http://www.opengeospatial.org/standards/sfa

WKB has to be forwards-compatible to the spec, so strict OGC WKB, and EWKB (PostGIS) are both ok. @author Robert Coup

Read More
Advertisement