private static void validateSphericalType(String function, OGCGeometry geometry, Set<GeometryType> validTypes) { GeometryType type = GeometryType.getForEsriGeometryType(geometry.geometryType()); if (!validTypes.contains(type)) { throw new PrestoException(INVALID_FUNCTION_ARGUMENT, format("When applied to SphericalGeography inputs, %s only supports %s. Input type is: %s", function, OR_JOINER.join(validTypes), type)); } }
private static void validateType(String function, OGCGeometry geometry, Set<GeometryType> validTypes) { GeometryType type = GeometryType.getForEsriGeometryType(geometry.geometryType()); if (!validTypes.contains(type)) { throw new PrestoException(INVALID_FUNCTION_ARGUMENT, format("%s only applies to %s. Input type is: %s", function, OR_JOINER.join(validTypes), type)); } } }
private static void validateType(String function, OGCGeometry geometry, Set<GeometryType> validTypes) { GeometryType type = GeometryType.getForEsriGeometryType(geometry.geometryType()); if (!validTypes.contains(type)) { throw new PrestoException(INVALID_FUNCTION_ARGUMENT, format("%s only applies to %s. Input type is: %s", function, OR_JOINER.join(validTypes), type)); } }
public void eval() { com.esri.core.geometry.ogc.OGCGeometry geom; geom = com.esri.core.geometry.ogc.OGCGeometry .fromBinary(geomParam.buffer.nioBuffer(geomParam.start, geomParam.end - geomParam.start)); if (geom != null && geom.geometryType().equals("Point")) { out.value = ((com.esri.core.geometry.ogc.OGCPoint) geom).Y(); } else { out.value = Double.NaN; } } }
public void eval() { com.esri.core.geometry.ogc.OGCGeometry geom; geom = com.esri.core.geometry.ogc.OGCGeometry .fromBinary(geomParam.buffer.nioBuffer(geomParam.start, geomParam.end - geomParam.start)); if (geom != null && geom.geometryType().equals("Point")) { out.value = ((com.esri.core.geometry.ogc.OGCPoint) geom).X(); } else { out.value = Double.NaN; } } }
public void eval() { com.esri.core.geometry.ogc.OGCGeometry geom1; geom1 = com.esri.core.geometry.ogc.OGCGeometry .fromBinary(geom1Param.buffer.nioBuffer(geom1Param.start, geom1Param.end - geom1Param.start)); com.esri.core.geometry.ogc.OGCGeometry envelopeGeom; if (geom1.geometryType().equals("Point")) { envelopeGeom = geom1; } else { envelopeGeom = geom1.envelope(); } java.nio.ByteBuffer envelopeGeomBytes = envelopeGeom.asBinary(); int outputSize = envelopeGeomBytes.remaining(); buffer = out.buffer = buffer.reallocIfNeeded(outputSize); out.start = 0; out.end = outputSize; buffer.setBytes(0, envelopeGeomBytes); } }
public void eval() { com.esri.core.geometry.ogc.OGCGeometry geom1; geom1 = com.esri.core.geometry.ogc.OGCGeometry .fromBinary(geom1Param.buffer.nioBuffer(geom1Param.start, geom1Param.end - geom1Param.start)); if (geom1.geometryType().equals("Point")) { out.value = ((com.esri.core.geometry.ogc.OGCPoint) geom1).Y(); } else { com.esri.core.geometry.Envelope envelope = new com.esri.core.geometry.Envelope(); geom1.getEsriGeometry().queryEnvelope(envelope); out.value = envelope.getYMin(); } } }
public void eval() { com.esri.core.geometry.ogc.OGCGeometry geom1; geom1 = com.esri.core.geometry.ogc.OGCGeometry .fromBinary(geom1Param.buffer.nioBuffer(geom1Param.start, geom1Param.end - geom1Param.start)); if (geom1.geometryType().equals("Point")) { out.value = ((com.esri.core.geometry.ogc.OGCPoint) geom1).X(); } else { com.esri.core.geometry.Envelope envelope = new com.esri.core.geometry.Envelope(); geom1.getEsriGeometry().queryEnvelope(envelope); out.value = envelope.getXMin(); } } }
public void eval() { com.esri.core.geometry.ogc.OGCGeometry geom1; geom1 = com.esri.core.geometry.ogc.OGCGeometry .fromBinary(geom1Param.buffer.nioBuffer(geom1Param.start, geom1Param.end - geom1Param.start)); if (geom1.geometryType().equals("Point")) { out.value = ((com.esri.core.geometry.ogc.OGCPoint) geom1).Y(); } else { com.esri.core.geometry.Envelope envelope = new com.esri.core.geometry.Envelope(); geom1.getEsriGeometry().queryEnvelope(envelope); out.value = envelope.getYMax(); } } }
public void eval() { com.esri.core.geometry.ogc.OGCGeometry geom1; geom1 = com.esri.core.geometry.ogc.OGCGeometry .fromBinary(geom1Param.buffer.nioBuffer(geom1Param.start, geom1Param.end - geom1Param.start)); if (geom1.geometryType().equals("Point")) { out.value = ((com.esri.core.geometry.ogc.OGCPoint) geom1).X(); } else { com.esri.core.geometry.Envelope envelope = new com.esri.core.geometry.Envelope(); geom1.getEsriGeometry().queryEnvelope(envelope); out.value = envelope.getXMax(); } } }
@Description("Returns the closure of the combinatorial boundary of this Geometry") @ScalarFunction("ST_Boundary") @SqlType(GEOMETRY_TYPE_NAME) public static Slice stBoundary(@SqlType(GEOMETRY_TYPE_NAME) Slice input) { OGCGeometry geometry = deserialize(input); if (geometry.isEmpty() && GeometryType.getForEsriGeometryType(geometry.geometryType()) == LINE_STRING) { // OCGGeometry#boundary crashes with NPE for LINESTRING EMPTY return EMPTY_MULTIPOINT; } return serialize(geometry.boundary()); }
private static void writeGeometry(DynamicSliceOutput output, OGCGeometry geometry) GeometryType type = GeometryType.getForEsriGeometryType(geometry.geometryType()); switch (type) { case POINT:
@Description("Returns the minimum convex geometry that encloses all input geometries") @ScalarFunction("ST_ConvexHull") @SqlType(GEOMETRY_TYPE_NAME) public static Slice stConvexHull(@SqlType(GEOMETRY_TYPE_NAME) Slice input) { OGCGeometry geometry = deserialize(input); if (geometry.isEmpty()) { return input; } if (GeometryType.getForEsriGeometryType(geometry.geometryType()) == POINT) { return input; } return serialize(geometry.convexHull()); }
@Description("Returns the cardinality of the geometry collection") @ScalarFunction("ST_NumGeometries") @SqlType(INTEGER) public static long stNumGeometries(@SqlType(GEOMETRY_TYPE_NAME) Slice input) { OGCGeometry geometry = deserialize(input); if (geometry.isEmpty()) { return 0; } GeometryType type = GeometryType.getForEsriGeometryType(geometry.geometryType()); if (!type.isMultitype()) { return 1; } return ((OGCGeometryCollection) geometry).numGeometries(); }
@SqlNullable @Description("Returns a multi-point geometry formed from input points") @ScalarFunction("ST_MultiPoint") @SqlType(GEOMETRY_TYPE_NAME) public static Slice stMultiPoint(@SqlType("array(" + GEOMETRY_TYPE_NAME + ")") Block input) { MultiPoint multipoint = new MultiPoint(); for (int i = 0; i < input.getPositionCount(); i++) { if (input.isNull(i)) { throw new PrestoException(INVALID_FUNCTION_ARGUMENT, format("Invalid input to ST_MultiPoint: null at index %s", i + 1)); } Slice slice = GEOMETRY.getSlice(input, i); OGCGeometry geometry = deserialize(slice); if (!(geometry instanceof OGCPoint)) { throw new PrestoException(INVALID_FUNCTION_ARGUMENT, format("Invalid input to ST_MultiPoint: geometry is not a point: %s at index %s", geometry.geometryType(), i + 1)); } OGCPoint point = (OGCPoint) geometry; if (point.isEmpty()) { throw new PrestoException(INVALID_FUNCTION_ARGUMENT, format("Invalid input to ST_MultiPoint: empty point at index %s", i + 1)); } multipoint.add(point.X(), point.Y()); } if (multipoint.getPointCount() == 0) { return null; } return serialize(createFromEsriGeometry(multipoint, null, true)); }
throw new PrestoException(INVALID_FUNCTION_ARGUMENT, format("ST_LineString takes only an array of valid points, %s was passed", geometry.geometryType()));
@Description("Returns the 2D Euclidean area of a geometry") @ScalarFunction("ST_Area") @SqlType(DOUBLE) public static double stArea(@SqlType(GEOMETRY_TYPE_NAME) Slice input) { OGCGeometry geometry = deserialize(input); // The Esri geometry library does not support area for geometry collections. We compute the area // of collections by summing the area of the individual components. GeometryType type = GeometryType.getForEsriGeometryType(geometry.geometryType()); if (type == GeometryType.GEOMETRY_COLLECTION) { double area = 0.0; GeometryCursor cursor = geometry.getEsriGeometryCursor(); while (true) { com.esri.core.geometry.Geometry esriGeometry = cursor.next(); if (esriGeometry == null) { return area; } area += esriGeometry.calculateArea2D(); } } return geometry.getEsriGeometry().calculateArea2D(); }
@SqlNullable @Description("Returns the geometry element at the specified index (indices started with 1)") @ScalarFunction("ST_GeometryN") @SqlType(GEOMETRY_TYPE_NAME) public static Slice stGeometryN(@SqlType(GEOMETRY_TYPE_NAME) Slice input, @SqlType(INTEGER) long index) { OGCGeometry geometry = deserialize(input); if (geometry.isEmpty()) { return null; } GeometryType type = GeometryType.getForEsriGeometryType(geometry.geometryType()); if (!type.isMultitype()) { if (index == 1) { return input; } return null; } OGCGeometryCollection geometryCollection = ((OGCGeometryCollection) geometry); if (index < 1 || index > geometryCollection.numGeometries()) { return null; } OGCGeometry ogcGeometry = geometryCollection.geometryN((int) index - 1); return serialize(ogcGeometry); }
GeometryType geometryType = GeometryType.getForEsriGeometryType(geometry.geometryType()); if (geometryType == GeometryType.POINT) { return input;
@SqlNullable @Description("Returns an array of geometries in the specified collection") @ScalarFunction("ST_Geometries") @SqlType("array(" + GEOMETRY_TYPE_NAME + ")") public static Block stGeometries(@SqlType(GEOMETRY_TYPE_NAME) Slice input) { OGCGeometry geometry = deserialize(input); if (geometry.isEmpty()) { return null; } GeometryType type = GeometryType.getForEsriGeometryType(geometry.geometryType()); if (!type.isMultitype()) { BlockBuilder blockBuilder = GEOMETRY.createBlockBuilder(null, 1); GEOMETRY.writeSlice(blockBuilder, serialize(geometry)); return blockBuilder.build(); } OGCGeometryCollection collection = (OGCGeometryCollection) geometry; BlockBuilder blockBuilder = GEOMETRY.createBlockBuilder(null, collection.numGeometries()); for (int i = 0; i < collection.numGeometries(); i++) { GEOMETRY.writeSlice(blockBuilder, serialize(collection.geometryN(i))); } return blockBuilder.build(); }