use of org.locationtech.jts.geom.impl.PackedCoordinateSequenceFactory in project presto by prestodb.
the class GeoFunctions method readPointCoordinates.
private static CoordinateSequence readPointCoordinates(Block input, String functionName, boolean forbidDuplicates) {
PackedCoordinateSequenceFactory coordinateSequenceFactory = new PackedCoordinateSequenceFactory();
double[] coordinates = new double[2 * input.getPositionCount()];
double lastX = Double.NaN;
double lastY = Double.NaN;
for (int i = 0; i < input.getPositionCount(); i++) {
if (input.isNull(i)) {
throw new PrestoException(INVALID_FUNCTION_ARGUMENT, format("Invalid input to %s: null at index %s", functionName, i + 1));
}
BasicSliceInput slice = new BasicSliceInput(GEOMETRY.getSlice(input, i));
GeometrySerializationType type = GeometrySerializationType.getForCode(slice.readByte());
if (type != GeometrySerializationType.POINT) {
throw new PrestoException(INVALID_FUNCTION_ARGUMENT, format("Invalid input to %s: geometry is not a point: %s at index %s", functionName, type.toString(), i + 1));
}
double x = slice.readDouble();
double y = slice.readDouble();
if (Double.isNaN(x) || Double.isNaN(x)) {
throw new PrestoException(INVALID_FUNCTION_ARGUMENT, format("Invalid input to %s: empty point at index %s", functionName, i + 1));
}
if (forbidDuplicates && x == lastX && y == lastY) {
throw new PrestoException(INVALID_FUNCTION_ARGUMENT, format("Invalid input to %s: consecutive duplicate points at index %s", functionName, i + 1));
}
lastX = x;
lastY = y;
coordinates[2 * i] = x;
coordinates[2 * i + 1] = y;
}
return coordinateSequenceFactory.create(coordinates, 2);
}
Aggregations