use of com.esri.core.geometry.Point in project presto by prestodb.
the class GeometryUtils method isPointOrRectangle.
public static boolean isPointOrRectangle(OGCGeometry ogcGeometry, Envelope envelope) {
if (ogcGeometry instanceof OGCPoint) {
return true;
}
if (!(ogcGeometry instanceof OGCPolygon)) {
return false;
}
Polygon polygon = (Polygon) ogcGeometry.getEsriGeometry();
if (polygon.getPathCount() > 1) {
return false;
}
if (polygon.getPointCount() != 4) {
return false;
}
Set<Point> corners = new HashSet<>();
corners.add(new Point(envelope.getXMin(), envelope.getYMin()));
corners.add(new Point(envelope.getXMin(), envelope.getYMax()));
corners.add(new Point(envelope.getXMax(), envelope.getYMin()));
corners.add(new Point(envelope.getXMax(), envelope.getYMax()));
for (int i = 0; i < 4; i++) {
Point point = polygon.getPoint(i);
if (!corners.contains(point)) {
return false;
}
}
return true;
}
use of com.esri.core.geometry.Point in project presto by prestodb.
the class SphericalGeographyUtils method sphericalDistance.
public static Double sphericalDistance(OGCGeometry leftGeometry, OGCGeometry rightGeometry) {
if (leftGeometry.isEmpty() || rightGeometry.isEmpty()) {
return null;
}
validateSphericalType("ST_Distance", leftGeometry, ALLOWED_SPHERICAL_DISTANCE_TYPES);
validateSphericalType("ST_Distance", rightGeometry, ALLOWED_SPHERICAL_DISTANCE_TYPES);
Point leftPoint = (Point) leftGeometry.getEsriGeometry();
Point rightPoint = (Point) rightGeometry.getEsriGeometry();
// greatCircleDistance returns distance in KM.
return greatCircleDistance(leftPoint.getY(), leftPoint.getX(), rightPoint.getY(), rightPoint.getX()) * 1000;
}
use of com.esri.core.geometry.Point in project presto by prestodb.
the class GeoFunctions method stY.
@SqlNullable
@Description("Return the Y coordinate of the point")
@ScalarFunction("ST_Y")
@SqlType(DOUBLE)
public static Double stY(@SqlType(GEOMETRY_TYPE_NAME) Slice input) {
Geometry geometry = deserialize(input);
validateType("ST_Y", geometry, EnumSet.of(POINT));
if (geometry.isEmpty()) {
return null;
}
return ((org.locationtech.jts.geom.Point) geometry).getY();
}
use of com.esri.core.geometry.Point in project presto by prestodb.
the class TestSphericalGeoFunctions method testSTSphericalCentroid.
@Test
public void testSTSphericalCentroid() {
// Spherical centroid testing
assertSphericalCentroid("POINT (3 5)", new Point(3, 5));
assertSphericalCentroid("POINT EMPTY", null);
assertSphericalCentroid("MULTIPOINT EMPTY", null);
assertSphericalCentroid("MULTIPOINT (3 5)", new Point(3, 5));
assertSphericalCentroid("MULTIPOINT (0 -45, 0 45)", new Point(0, 0));
assertSphericalCentroid("MULTIPOINT (45 0, -45 0)", new Point(0, 0));
assertSphericalCentroid("MULTIPOINT (0 0, -180 0)", new Point(-90, 45));
assertSphericalCentroid("MULTIPOINT (0 -45, 0 45, 30 0)", new Point(12.36780515862267, 0));
assertSphericalCentroid("MULTIPOINT (0 -45, 0 45, 30 0, -30 0)", new Point(0, 0));
}
use of com.esri.core.geometry.Point in project presto by prestodb.
the class TestSphericalGeoFunctions method testGetObjectValue.
@Test
public void testGetObjectValue() {
List<String> wktList = ImmutableList.of("POINT EMPTY", "MULTIPOINT EMPTY", "LINESTRING EMPTY", "MULTILINESTRING EMPTY", "POLYGON EMPTY", "MULTIPOLYGON EMPTY", "GEOMETRYCOLLECTION EMPTY", "POINT (-40.2 28.9)", "MULTIPOINT ((-40.2 28.9), (-40.2 31.9))", "LINESTRING (-40.2 28.9, -40.2 31.9, -37.2 31.9)", "MULTILINESTRING ((-40.2 28.9, -40.2 31.9), (-40.2 31.9, -37.2 31.9))", "POLYGON ((-40.2 28.9, -37.2 28.9, -37.2 31.9, -40.2 31.9, -40.2 28.9))", "POLYGON ((-40.2 28.9, -37.2 28.9, -37.2 31.9, -40.2 31.9, -40.2 28.9), (-39.2 29.9, -39.2 30.9, -38.2 30.9, -38.2 29.9, -39.2 29.9))", "MULTIPOLYGON (((-40.2 28.9, -37.2 28.9, -37.2 31.9, -40.2 31.9, -40.2 28.9)), ((-39.2 29.9, -38.2 29.9, -38.2 30.9, -39.2 30.9, -39.2 29.9)))", "GEOMETRYCOLLECTION (POINT (-40.2 28.9), LINESTRING (-40.2 28.9, -40.2 31.9, -37.2 31.9), POLYGON ((-40.2 28.9, -37.2 28.9, -37.2 31.9, -40.2 31.9, -40.2 28.9)))");
BlockBuilder builder = SPHERICAL_GEOGRAPHY.createBlockBuilder(null, wktList.size());
for (String wkt : wktList) {
SPHERICAL_GEOGRAPHY.writeSlice(builder, toSphericalGeography(GeoFunctions.stGeometryFromText(utf8Slice(wkt))));
}
Block block = builder.build();
for (int i = 0; i < wktList.size(); i++) {
assertEquals(wktList.get(i), SPHERICAL_GEOGRAPHY.getObjectValue(null, block, i));
}
}
Aggregations