use of com.esri.core.geometry.Envelope in project presto by prestodb.
the class GeoFunctions method envelopes.
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);
}
use of com.esri.core.geometry.Envelope in project presto by prestodb.
the class GeoFunctions method stEnvelopeAsPts.
@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);
org.locationtech.jts.geom.Point lowerLeftCorner = createJtsPoint(envelope.getXMin(), envelope.getYMin());
org.locationtech.jts.geom.Point upperRightCorner = createJtsPoint(envelope.getXMax(), envelope.getYMax());
GEOMETRY.writeSlice(blockBuilder, serialize(lowerLeftCorner));
GEOMETRY.writeSlice(blockBuilder, serialize(upperRightCorner));
return blockBuilder.build();
}
use of com.esri.core.geometry.Envelope in project presto by prestodb.
the class GeoFunctions method stIntersection.
@Description("Returns the Geometry value that represents the point set intersection of two Geometries")
@ScalarFunction("ST_Intersection")
@SqlType(GEOMETRY_TYPE_NAME)
public static Slice stIntersection(@SqlType(GEOMETRY_TYPE_NAME) Slice left, @SqlType(GEOMETRY_TYPE_NAME) Slice right) {
GeometrySerializationType leftType = deserializeType(left);
GeometrySerializationType rightType = deserializeType(right);
if (leftType == GeometrySerializationType.ENVELOPE && rightType == GeometrySerializationType.ENVELOPE) {
Envelope leftEnvelope = deserializeEnvelope(left);
Envelope rightEnvelope = deserializeEnvelope(right);
// Envelope#intersect updates leftEnvelope to the intersection of the two envelopes
if (!leftEnvelope.intersect(rightEnvelope)) {
return EMPTY_POLYGON;
}
Envelope intersection = leftEnvelope;
if (intersection.getXMin() == intersection.getXMax() || intersection.getYMin() == intersection.getYMax()) {
if (intersection.getXMin() == intersection.getXMax() && intersection.getYMin() == intersection.getYMax()) {
return EsriGeometrySerde.serialize(createFromEsriGeometry(new Point(intersection.getXMin(), intersection.getYMin()), null));
}
return EsriGeometrySerde.serialize(createFromEsriGeometry(new Polyline(new Point(intersection.getXMin(), intersection.getYMin()), new Point(intersection.getXMax(), intersection.getYMax())), null));
}
return EsriGeometrySerde.serialize(intersection);
}
// If one side is an envelope, then if it contains the other's envelope we can just return the other geometry.
if (leftType == GeometrySerializationType.ENVELOPE && deserializeEnvelope(left).contains(deserializeEnvelope(right))) {
return right;
}
if (rightType == GeometrySerializationType.ENVELOPE && deserializeEnvelope(right).contains(deserializeEnvelope(left))) {
return left;
}
OGCGeometry leftGeometry = EsriGeometrySerde.deserialize(left);
OGCGeometry rightGeometry = EsriGeometrySerde.deserialize(right);
verifySameSpatialReference(leftGeometry, rightGeometry);
return EsriGeometrySerde.serialize(leftGeometry.intersection(rightGeometry));
}
use of com.esri.core.geometry.Envelope in project presto by prestodb.
the class SphericalGeoFunctions method spatialPartitions.
@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(int)")
public static Block spatialPartitions(@SqlType(KdbTreeType.NAME) Object kdbTree, @SqlType(SPHERICAL_GEOGRAPHY_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 GeoFunctions.spatialPartitions((KdbTree) kdbTree, expandedEnvelope2D);
}
use of com.esri.core.geometry.Envelope in project presto by prestodb.
the class SphericalGeoFunctions method toSphericalGeography.
@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 = EsriGeometrySerde.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;
}
Aggregations