public void eval() { double bufferRadius = bufferRadiusParam.value; com.esri.core.geometry.ogc.OGCGeometry geom1 = com.esri.core.geometry.ogc.OGCGeometry .fromBinary(geom1Param.buffer.nioBuffer(geom1Param.start, geom1Param.end - geom1Param.start)); com.esri.core.geometry.ogc.OGCGeometry bufferedGeom = geom1.buffer(bufferRadius); java.nio.ByteBuffer bufferedGeomBytes = bufferedGeom.asBinary(); int outputSize = bufferedGeomBytes.remaining(); buffer = out.buffer = buffer.reallocIfNeeded(outputSize); out.start = 0; out.end = outputSize; buffer.setBytes(0, bufferedGeomBytes); } }
@SqlNullable @Description("Returns the geometry that represents all points whose distance from the specified geometry is less than or equal to the specified distance") @ScalarFunction("ST_Buffer") @SqlType(GEOMETRY_TYPE_NAME) public static Slice stBuffer(@SqlType(GEOMETRY_TYPE_NAME) Slice input, @SqlType(DOUBLE) double distance) { if (isNaN(distance)) { throw new PrestoException(INVALID_FUNCTION_ARGUMENT, "distance is NaN"); } if (distance < 0) { throw new PrestoException(INVALID_FUNCTION_ARGUMENT, "distance is negative"); } if (distance == 0) { return input; } OGCGeometry geometry = deserialize(input); if (geometry.isEmpty()) { return null; } return serialize(geometry.buffer(distance)); }
@Override public DataByteArray exec(Tuple input) throws IOException { OGCGeometry geom = null; try { Object v = input.get(0); geom = geometryParser.parseGeom(v); double dist; Object distance = input.get(1); if (distance instanceof Double) dist = (Double) distance; else if (distance instanceof Float) dist = (Float) distance; else if (distance instanceof Integer) dist = (Integer) distance; else if (distance instanceof Long) dist = (Long) distance; else if (distance instanceof String) dist = Double.parseDouble((String) distance); else if (distance instanceof DataByteArray) dist = Double.parseDouble(new String(((DataByteArray) distance).get())); else throw new GeoException("Invalid second argument in call to Buffer. Expecting Double, Integer or Long"); return new DataByteArray(geom.buffer(dist).asBinary().array()); } catch (ExecException ee) { throw new GeoException(geom, ee); } }
public BytesWritable evaluate(BytesWritable geometryref1, DoubleWritable distance) { if (geometryref1 == null || geometryref1.getLength() == 0 || distance == null) { return null; } OGCGeometry ogcGeometry = GeometryUtils.geometryFromEsriShape(geometryref1); if (ogcGeometry == null){ LogUtils.Log_ArgumentsNull(LOG); return null; } OGCGeometry bufferedGeometry = ogcGeometry.buffer(distance.get()); // TODO persist type information (polygon vs multipolygon) return GeometryUtils.geometryToEsriShapeBytesWritable(bufferedGeometry); } }
@SqlNullable @Description("Returns the geometry that represents all points whose distance from the specified geometry is less than or equal to the specified distance") @ScalarFunction("ST_Buffer") @SqlType(GEOMETRY_TYPE_NAME) public static Slice stBuffer(@SqlType(GEOMETRY_TYPE_NAME) Slice input, @SqlType(DOUBLE) double distance) { if (isNaN(distance)) { throw new PrestoException(INVALID_FUNCTION_ARGUMENT, "distance is NaN"); } if (distance < 0) { throw new PrestoException(INVALID_FUNCTION_ARGUMENT, "distance is negative"); } if (distance == 0) { return input; } OGCGeometry geometry = deserialize(input); if (geometry.isEmpty()) { return null; } return serialize(geometry.buffer(distance)); }
@SqlNullable @Description("Returns the geometry that represents all points whose distance from the specified geometry is less than or equal to the specified distance") @ScalarFunction("ST_Buffer") @SqlType(GEOMETRY_TYPE_NAME) public static Slice stBuffer(@SqlType(GEOMETRY_TYPE_NAME) Slice input, @SqlType(DOUBLE) double distance) { if (isNaN(distance)) { throw new PrestoException(INVALID_FUNCTION_ARGUMENT, "distance is NaN"); } if (distance < 0) { throw new PrestoException(INVALID_FUNCTION_ARGUMENT, "distance is negative"); } if (distance == 0) { return input; } OGCGeometry geometry = deserialize(input); if (geometry.isEmpty()) { return null; } return serialize(geometry.buffer(distance)); }