use of com.esri.core.geometry.ogc.OGCGeometry in project pigeon by aseldawy.
the class Area method exec.
@Override
public Double exec(Tuple input) throws IOException {
OGCGeometry geom = null;
try {
Object v = input.get(0);
geom = geometryParser.parseGeom(v);
return geom.getEsriGeometry().calculateArea2D();
} catch (ExecException ee) {
throw new GeoException(geom, ee);
}
}
use of com.esri.core.geometry.ogc.OGCGeometry in project presto by prestodb.
the class GeoFunctions method flattenGeometryCollections.
@Description("Recursively flattens GeometryCollections")
@ScalarFunction("flatten_geometry_collections")
@SqlType("array(" + GEOMETRY_TYPE_NAME + ")")
public static Block flattenGeometryCollections(@SqlType(GEOMETRY_TYPE_NAME) Slice input) {
OGCGeometry geometry = EsriGeometrySerde.deserialize(input);
List<OGCGeometry> components = Streams.stream(flattenCollection(geometry)).collect(toImmutableList());
BlockBuilder blockBuilder = GEOMETRY.createBlockBuilder(null, components.size());
for (OGCGeometry component : components) {
GEOMETRY.writeSlice(blockBuilder, EsriGeometrySerde.serialize(component));
}
return blockBuilder.build();
}
use of com.esri.core.geometry.ogc.OGCGeometry in project presto by prestodb.
the class GeoFunctions method stIsRing.
@SqlNullable
@Description("Returns TRUE if and only if the line is closed and simple")
@ScalarFunction("ST_IsRing")
@SqlType(BOOLEAN)
public static Boolean stIsRing(@SqlType(GEOMETRY_TYPE_NAME) Slice input) {
OGCGeometry geometry = EsriGeometrySerde.deserialize(input);
validateType("ST_IsRing", geometry, EnumSet.of(LINE_STRING));
OGCLineString line = (OGCLineString) geometry;
return line.isClosed() && line.isSimple();
}
use of com.esri.core.geometry.ogc.OGCGeometry in project presto by prestodb.
the class GeoFunctions method stCrosses.
@SqlNullable
@Description("Returns TRUE if the supplied geometries have some, but not all, interior points in common")
@ScalarFunction("ST_Crosses")
@SqlType(BOOLEAN)
public static Boolean stCrosses(@SqlType(GEOMETRY_TYPE_NAME) Slice left, @SqlType(GEOMETRY_TYPE_NAME) Slice right) {
if (!envelopes(left, right, Envelope::intersect)) {
return false;
}
OGCGeometry leftGeometry = EsriGeometrySerde.deserialize(left);
OGCGeometry rightGeometry = EsriGeometrySerde.deserialize(right);
verifySameSpatialReference(leftGeometry, rightGeometry);
return leftGeometry.crosses(rightGeometry);
}
use of com.esri.core.geometry.ogc.OGCGeometry 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));
}
Aggregations