Search in sources :

Example 31 with OGCGeometry

use of com.esri.core.geometry.ogc.OGCGeometry in project presto by prestodb.

the class EsriGeometrySerde method readGeometryCollection.

private static OGCConcreteGeometryCollection readGeometryCollection(BasicSliceInput input, Slice inputSlice) {
    // GeometryCollection: geometryType|len-of-shape1|bytes-of-shape1|len-of-shape2|bytes-of-shape2...
    List<OGCGeometry> geometries = new ArrayList<>();
    while (input.available() > 0) {
        int length = input.readInt() - 1;
        GeometrySerializationType type = GeometrySerializationType.getForCode(input.readByte());
        geometries.add(readGeometry(input, inputSlice, type, length));
    }
    return new OGCConcreteGeometryCollection(geometries, null);
}
Also used : OGCGeometry(com.esri.core.geometry.ogc.OGCGeometry) ArrayList(java.util.ArrayList) OGCConcreteGeometryCollection(com.esri.core.geometry.ogc.OGCConcreteGeometryCollection) OGCPoint(com.esri.core.geometry.ogc.OGCPoint) MultiPoint(com.esri.core.geometry.MultiPoint) OGCMultiPoint(com.esri.core.geometry.ogc.OGCMultiPoint) Point(com.esri.core.geometry.Point)

Example 32 with OGCGeometry

use of com.esri.core.geometry.ogc.OGCGeometry in project presto by prestodb.

the class EsriGeometrySerde method writePoint.

private static void writePoint(DynamicSliceOutput output, OGCGeometry geometry) {
    Geometry esriGeometry = geometry.getEsriGeometry();
    verify(esriGeometry instanceof Point, "geometry is expected to be an instance of Point");
    Point point = (Point) esriGeometry;
    verify(!point.hasAttribute(VertexDescription.Semantics.Z) && !point.hasAttribute(VertexDescription.Semantics.M) && !point.hasAttribute(VertexDescription.Semantics.ID), "Only 2D points with no ID nor M attribute are supported");
    output.appendByte(GeometrySerializationType.POINT.code());
    if (!point.isEmpty()) {
        output.appendDouble(point.getX());
        output.appendDouble(point.getY());
    } else {
        output.appendDouble(NaN);
        output.appendDouble(NaN);
    }
}
Also used : OGCGeometry(com.esri.core.geometry.ogc.OGCGeometry) Geometry(com.esri.core.geometry.Geometry) OGCPoint(com.esri.core.geometry.ogc.OGCPoint) MultiPoint(com.esri.core.geometry.MultiPoint) OGCMultiPoint(com.esri.core.geometry.ogc.OGCMultiPoint) Point(com.esri.core.geometry.Point)

Example 33 with OGCGeometry

use of com.esri.core.geometry.ogc.OGCGeometry in project presto by prestodb.

the class EsriGeometrySerde method writeSimpleGeometry.

private static void writeSimpleGeometry(DynamicSliceOutput output, GeometrySerializationType type, OGCGeometry geometry) {
    output.appendByte(type.code());
    Geometry esriGeometry = requireNonNull(geometry.getEsriGeometry(), "esriGeometry is null");
    byte[] shape = geometryToEsriShape(esriGeometry);
    output.appendBytes(shape);
}
Also used : OGCGeometry(com.esri.core.geometry.ogc.OGCGeometry) Geometry(com.esri.core.geometry.Geometry)

Example 34 with OGCGeometry

use of com.esri.core.geometry.ogc.OGCGeometry in project presto by prestodb.

the class EsriGeometrySerde method readSimpleGeometry.

private static OGCGeometry readSimpleGeometry(BasicSliceInput input, Slice inputSlice, GeometrySerializationType type, int length) {
    int currentPosition = toIntExact(input.position());
    ByteBuffer geometryBuffer = inputSlice.toByteBuffer(currentPosition, length).slice();
    input.setPosition(currentPosition + length);
    Geometry esriGeometry = OperatorImportFromESRIShape.local().execute(0, Unknown, geometryBuffer);
    return createFromEsriGeometry(esriGeometry, type.geometryType().isMultitype());
}
Also used : OGCGeometry(com.esri.core.geometry.ogc.OGCGeometry) Geometry(com.esri.core.geometry.Geometry) ByteBuffer(java.nio.ByteBuffer) OGCPoint(com.esri.core.geometry.ogc.OGCPoint) MultiPoint(com.esri.core.geometry.MultiPoint) OGCMultiPoint(com.esri.core.geometry.ogc.OGCMultiPoint) Point(com.esri.core.geometry.Point)

Example 35 with OGCGeometry

use of com.esri.core.geometry.ogc.OGCGeometry in project presto by prestodb.

the class EsriGeometrySerde method writeGeometryCollection.

private static void writeGeometryCollection(DynamicSliceOutput output, OGCGeometryCollection collection) {
    output.appendByte(GeometrySerializationType.GEOMETRY_COLLECTION.code());
    for (int geometryIndex = 0; geometryIndex < collection.numGeometries(); geometryIndex++) {
        OGCGeometry geometry = collection.geometryN(geometryIndex);
        int startPosition = output.size();
        // leave 4 bytes for the shape length
        output.appendInt(0);
        writeGeometry(output, geometry);
        int endPosition = output.size();
        int length = endPosition - startPosition - Integer.BYTES;
        output.getUnderlyingSlice().setInt(startPosition, length);
    }
}
Also used : OGCGeometry(com.esri.core.geometry.ogc.OGCGeometry) OGCPoint(com.esri.core.geometry.ogc.OGCPoint) MultiPoint(com.esri.core.geometry.MultiPoint) OGCMultiPoint(com.esri.core.geometry.ogc.OGCMultiPoint) Point(com.esri.core.geometry.Point)

Aggregations

OGCGeometry (com.esri.core.geometry.ogc.OGCGeometry)66 SqlType (com.facebook.presto.spi.function.SqlType)22 Description (com.facebook.presto.spi.function.Description)21 ScalarFunction (com.facebook.presto.spi.function.ScalarFunction)21 SqlNullable (com.facebook.presto.spi.function.SqlNullable)14 Point (com.esri.core.geometry.Point)12 ExecException (org.apache.pig.backend.executionengine.ExecException)12 DataByteArray (org.apache.pig.data.DataByteArray)8 Geometry (com.esri.core.geometry.Geometry)7 OGCPoint (com.esri.core.geometry.ogc.OGCPoint)7 Envelope (com.esri.core.geometry.Envelope)6 OGCConcreteGeometryCollection (com.esri.core.geometry.ogc.OGCConcreteGeometryCollection)6 OGCGeometryCollection (com.esri.core.geometry.ogc.OGCGeometryCollection)6 ArrayList (java.util.ArrayList)6 Slice (io.airlift.slice.Slice)5 GeometryCursor (com.esri.core.geometry.GeometryCursor)4 MultiPoint (com.esri.core.geometry.MultiPoint)4 OGCMultiPoint (com.esri.core.geometry.ogc.OGCMultiPoint)4 Tuple (org.apache.pig.data.Tuple)4 Page (com.facebook.presto.common.Page)3