Java Code Examples for com.esri.core.geometry.Envelope#isEmpty()

The following examples show how to use com.esri.core.geometry.Envelope#isEmpty() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GeoFunctions.java    From presto with Apache License 2.0 6 votes vote down vote up
@SqlNullable
@Description("Returns the lower left and upper right corners of bounding rectangular polygon of a Geometry")
@ScalarFunction("ST_EnvelopeAsPts")
@SqlType("array(" + GEOMETRY_TYPE_NAME + ")")
public static Block stEnvelopeAsPts(@SqlType(GEOMETRY_TYPE_NAME) Slice input)
{
    Envelope envelope = deserializeEnvelope(input);
    if (envelope.isEmpty()) {
        return null;
    }
    BlockBuilder blockBuilder = GEOMETRY.createBlockBuilder(null, 2);
    Point lowerLeftCorner = new Point(envelope.getXMin(), envelope.getYMin());
    Point upperRightCorner = new Point(envelope.getXMax(), envelope.getYMax());
    GEOMETRY.writeSlice(blockBuilder, serialize(createFromEsriGeometry(lowerLeftCorner, null, false)));
    GEOMETRY.writeSlice(blockBuilder, serialize(createFromEsriGeometry(upperRightCorner, null, false)));
    return blockBuilder.build();
}
 
Example 2
Source File: GeoFunctions.java    From presto with Apache License 2.0 6 votes vote down vote up
@ScalarFunction
@SqlNullable
@Description("Returns an array of spatial partition IDs for a geometry representing a set of points within specified distance from the input geometry")
@SqlType("array(integer)")
public static Block spatialPartitions(@SqlType(KdbTreeType.NAME) Object kdbTree, @SqlType(GEOMETRY_TYPE_NAME) Slice geometry, @SqlType(DOUBLE) double distance)
{
    if (isNaN(distance)) {
        throw new PrestoException(INVALID_FUNCTION_ARGUMENT, "distance is NaN");
    }

    if (isInfinite(distance)) {
        throw new PrestoException(INVALID_FUNCTION_ARGUMENT, "distance is infinite");
    }

    if (distance < 0) {
        throw new PrestoException(INVALID_FUNCTION_ARGUMENT, "distance is negative");
    }

    Envelope envelope = deserializeEnvelope(geometry);
    if (envelope.isEmpty()) {
        return null;
    }

    Rectangle expandedEnvelope2D = new Rectangle(envelope.getXMin() - distance, envelope.getYMin() - distance, envelope.getXMax() + distance, envelope.getYMax() + distance);
    return spatialPartitions((KdbTree) kdbTree, expandedEnvelope2D);
}
 
Example 3
Source File: GeoFunctions.java    From presto with Apache License 2.0 5 votes vote down vote up
@Description("Converts a Geometry object to a SphericalGeography object")
@ScalarFunction("to_spherical_geography")
@SqlType(SPHERICAL_GEOGRAPHY_TYPE_NAME)
public static Slice toSphericalGeography(@SqlType(GEOMETRY_TYPE_NAME) Slice input)
{
    // "every point in input is in range" <=> "the envelope of input is in range"
    Envelope envelope = deserializeEnvelope(input);
    if (!envelope.isEmpty()) {
        checkLatitude(envelope.getYMin());
        checkLatitude(envelope.getYMax());
        checkLongitude(envelope.getXMin());
        checkLongitude(envelope.getXMax());
    }
    OGCGeometry geometry = deserialize(input);
    if (geometry.is3D()) {
        throw new PrestoException(INVALID_FUNCTION_ARGUMENT, "Cannot convert 3D geometry to a spherical geography");
    }

    GeometryCursor cursor = geometry.getEsriGeometryCursor();
    while (true) {
        com.esri.core.geometry.Geometry subGeometry = cursor.next();
        if (subGeometry == null) {
            break;
        }

        if (!GEOMETRY_TYPES_FOR_SPHERICAL_GEOGRAPHY.contains(subGeometry.getType())) {
            throw new PrestoException(INVALID_FUNCTION_ARGUMENT, "Cannot convert geometry of this type to spherical geography: " + subGeometry.getType());
        }
    }

    return input;
}
 
Example 4
Source File: GeoFunctions.java    From presto with Apache License 2.0 5 votes vote down vote up
@SqlNullable
@Description("Returns X maxima of a bounding box of a Geometry")
@ScalarFunction("ST_XMax")
@SqlType(DOUBLE)
public static Double stXMax(@SqlType(GEOMETRY_TYPE_NAME) Slice input)
{
    Envelope envelope = deserializeEnvelope(input);
    if (envelope.isEmpty()) {
        return null;
    }
    return envelope.getXMax();
}
 
Example 5
Source File: GeoFunctions.java    From presto with Apache License 2.0 5 votes vote down vote up
@SqlNullable
@Description("Returns Y maxima of a bounding box of a Geometry")
@ScalarFunction("ST_YMax")
@SqlType(DOUBLE)
public static Double stYMax(@SqlType(GEOMETRY_TYPE_NAME) Slice input)
{
    Envelope envelope = deserializeEnvelope(input);
    if (envelope.isEmpty()) {
        return null;
    }
    return envelope.getYMax();
}
 
Example 6
Source File: GeoFunctions.java    From presto with Apache License 2.0 5 votes vote down vote up
@SqlNullable
@Description("Returns X minima of a bounding box of a Geometry")
@ScalarFunction("ST_XMin")
@SqlType(DOUBLE)
public static Double stXMin(@SqlType(GEOMETRY_TYPE_NAME) Slice input)
{
    Envelope envelope = deserializeEnvelope(input);
    if (envelope.isEmpty()) {
        return null;
    }
    return envelope.getXMin();
}
 
Example 7
Source File: GeoFunctions.java    From presto with Apache License 2.0 5 votes vote down vote up
@SqlNullable
@Description("Returns Y minima of a bounding box of a Geometry")
@ScalarFunction("ST_YMin")
@SqlType(DOUBLE)
public static Double stYMin(@SqlType(GEOMETRY_TYPE_NAME) Slice input)
{
    Envelope envelope = deserializeEnvelope(input);
    if (envelope.isEmpty()) {
        return null;
    }
    return envelope.getYMin();
}
 
Example 8
Source File: GeoFunctions.java    From presto with Apache License 2.0 5 votes vote down vote up
@Description("Returns the bounding rectangular polygon of a Geometry")
@ScalarFunction("ST_Envelope")
@SqlType(GEOMETRY_TYPE_NAME)
public static Slice stEnvelope(@SqlType(GEOMETRY_TYPE_NAME) Slice input)
{
    Envelope envelope = deserializeEnvelope(input);
    if (envelope.isEmpty()) {
        return EMPTY_POLYGON;
    }
    return serialize(envelope);
}
 
Example 9
Source File: GeoFunctions.java    From presto with Apache License 2.0 5 votes vote down vote up
@ScalarFunction
@SqlNullable
@Description("Returns an array of spatial partition IDs for a given geometry")
@SqlType("array(integer)")
public static Block spatialPartitions(@SqlType(KdbTreeType.NAME) Object kdbTree, @SqlType(GEOMETRY_TYPE_NAME) Slice geometry)
{
    Envelope envelope = deserializeEnvelope(geometry);
    if (envelope.isEmpty()) {
        // Empty geometry
        return null;
    }

    return spatialPartitions((KdbTree) kdbTree, new Rectangle(envelope.getXMin(), envelope.getYMin(), envelope.getXMax(), envelope.getYMax()));
}
 
Example 10
Source File: GeoFunctions.java    From presto with Apache License 2.0 5 votes vote down vote up
private static boolean envelopes(Slice left, Slice right, EnvelopesPredicate predicate)
{
    Envelope leftEnvelope = deserializeEnvelope(left);
    Envelope rightEnvelope = deserializeEnvelope(right);
    if (leftEnvelope.isEmpty() || rightEnvelope.isEmpty()) {
        return false;
    }
    return predicate.apply(leftEnvelope, rightEnvelope);
}
 
Example 11
Source File: SpatialPartitioningInternalAggregateFunction.java    From presto with Apache License 2.0 5 votes vote down vote up
@InputFunction
public static void input(SpatialPartitioningState state, @SqlType(GEOMETRY_TYPE_NAME) Slice slice, @SqlType(INTEGER) long partitionCount)
{
    Envelope envelope = deserializeEnvelope(slice);
    if (envelope.isEmpty()) {
        return;
    }

    Rectangle extent = new Rectangle(envelope.getXMin(), envelope.getYMin(), envelope.getXMax(), envelope.getYMax());

    if (state.getCount() == 0) {
        state.setPartitionCount(toIntExact(partitionCount));
        state.setExtent(extent);
        state.setSamples(new ArrayList<>());
    }
    else {
        state.setExtent(state.getExtent().merge(extent));
    }

    // use reservoir sampling
    List<Rectangle> samples = state.getSamples();
    if (samples.size() <= MAX_SAMPLE_COUNT) {
        samples.add(extent);
    }
    else {
        long sampleIndex = ThreadLocalRandom.current().nextLong(state.getCount());
        if (sampleIndex < MAX_SAMPLE_COUNT) {
            samples.set(toIntExact(sampleIndex), extent);
        }
    }

    state.setCount(state.getCount() + 1);
}
 
Example 12
Source File: GeometrySerde.java    From presto with Apache License 2.0 5 votes vote down vote up
private static void writeEnvelopeCoordinates(DynamicSliceOutput output, Envelope envelope)
{
    if (envelope.isEmpty()) {
        output.appendDouble(NaN);
        output.appendDouble(NaN);
        output.appendDouble(NaN);
        output.appendDouble(NaN);
    }
    else {
        output.appendDouble(envelope.getXMin());
        output.appendDouble(envelope.getYMin());
        output.appendDouble(envelope.getXMax());
        output.appendDouble(envelope.getYMax());
    }
}