use of com.esri.core.geometry.ogc.OGCGeometry in project presto by prestodb.
the class AbstractTestGeoAggregationFunctions method assertAggregatedGeometries.
protected void assertAggregatedGeometries(String testDescription, String expectedWkt, String... wkts) {
List<Slice> geometrySlices = Arrays.stream(wkts).map(text -> text == null ? null : OGCGeometry.fromText(text)).map(input -> input == null ? null : EsriGeometrySerde.serialize(input)).collect(Collectors.toList());
// Add a custom equality assertion because the resulting geometry may have
// its constituent points in a different order
BiFunction<Object, Object, Boolean> equalityFunction = (left, right) -> {
if (left == null && right == null) {
return true;
}
if (left == null || right == null) {
return false;
}
OGCGeometry leftGeometry = OGCGeometry.fromText(left.toString());
OGCGeometry rightGeometry = OGCGeometry.fromText(right.toString());
// Check for equality by getting the difference
return leftGeometry.difference(rightGeometry).isEmpty() && rightGeometry.difference(leftGeometry).isEmpty();
};
// Test in forward and reverse order to verify that ordering doesn't affect the output
assertAggregation(function, equalityFunction, testDescription, new Page(BlockAssertions.createSlicesBlock(geometrySlices)), expectedWkt);
Collections.reverse(geometrySlices);
assertAggregation(function, equalityFunction, testDescription, new Page(BlockAssertions.createSlicesBlock(geometrySlices)), expectedWkt);
}
use of com.esri.core.geometry.ogc.OGCGeometry in project presto by prestodb.
the class TestGeometryStateFactory method testMemoryAccounting.
@Test
public void testMemoryAccounting() {
GeometryState state = factory.createGroupedState();
long oldSize = state.getEstimatedSize();
OGCGeometry geometry = OGCGeometry.fromText("POLYGON ((2 2, 1 1, 3 1, 2 2))");
long previousGeometryMemorySize = 0;
state.setGeometry(geometry, previousGeometryMemorySize);
assertTrue(oldSize < state.getEstimatedSize(), format("Expected old size %s to be less than new estimate %s", oldSize, state.getEstimatedSize()));
oldSize = state.getEstimatedSize();
previousGeometryMemorySize = state.getGeometry().estimateMemorySize();
state.setGeometry(state.getGeometry().union(geometry), previousGeometryMemorySize);
assertTrue(oldSize <= state.getEstimatedSize(), format("Expected old size %s to be less than or equal to new estimate %s", oldSize, state.getEstimatedSize()));
}
use of com.esri.core.geometry.ogc.OGCGeometry in project presto by prestodb.
the class GeoFunctions method stWithin.
@SqlNullable
@Description("Returns TRUE if the geometry A is completely inside geometry B")
@ScalarFunction("ST_Within")
@SqlType(BOOLEAN)
public static Boolean stWithin(@SqlType(GEOMETRY_TYPE_NAME) Slice left, @SqlType(GEOMETRY_TYPE_NAME) Slice right) {
if (!envelopes(right, left, Envelope::contains)) {
return false;
}
OGCGeometry leftGeometry = EsriGeometrySerde.deserialize(left);
OGCGeometry rightGeometry = EsriGeometrySerde.deserialize(right);
verifySameSpatialReference(leftGeometry, rightGeometry);
return leftGeometry.within(rightGeometry);
}
use of com.esri.core.geometry.ogc.OGCGeometry in project presto by prestodb.
the class GeoFunctions method stDisjoint.
@SqlNullable
@Description("Returns TRUE if the Geometries do not spatially intersect - if they do not share any space together")
@ScalarFunction("ST_Disjoint")
@SqlType(BOOLEAN)
public static Boolean stDisjoint(@SqlType(GEOMETRY_TYPE_NAME) Slice left, @SqlType(GEOMETRY_TYPE_NAME) Slice right) {
if (!envelopes(left, right, Envelope::intersect)) {
return true;
}
OGCGeometry leftGeometry = EsriGeometrySerde.deserialize(left);
OGCGeometry rightGeometry = EsriGeometrySerde.deserialize(right);
verifySameSpatialReference(leftGeometry, rightGeometry);
return leftGeometry.disjoint(rightGeometry);
}
use of com.esri.core.geometry.ogc.OGCGeometry in project presto by prestodb.
the class GeoFunctions method stContains.
@SqlNullable
@Description("Returns TRUE if and only if no points of right lie in the exterior of left, and at least one point of the interior of left lies in the interior of right")
@ScalarFunction("ST_Contains")
@SqlType(BOOLEAN)
public static Boolean stContains(@SqlType(GEOMETRY_TYPE_NAME) Slice left, @SqlType(GEOMETRY_TYPE_NAME) Slice right) {
if (!envelopes(left, right, Envelope::contains)) {
return false;
}
OGCGeometry leftGeometry = EsriGeometrySerde.deserialize(left);
OGCGeometry rightGeometry = EsriGeometrySerde.deserialize(right);
verifySameSpatialReference(leftGeometry, rightGeometry);
return leftGeometry.contains(rightGeometry);
}
Aggregations