Search in sources :

Example 26 with Point

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;
}
Also used : OGCPoint(com.esri.core.geometry.ogc.OGCPoint) OGCPolygon(com.esri.core.geometry.ogc.OGCPolygon) OGCPoint(com.esri.core.geometry.ogc.OGCPoint) Point(com.esri.core.geometry.Point) OGCPolygon(com.esri.core.geometry.ogc.OGCPolygon) Polygon(com.esri.core.geometry.Polygon) OGCPoint(com.esri.core.geometry.ogc.OGCPoint) Point(com.esri.core.geometry.Point) HashSet(java.util.HashSet)

Example 27 with Point

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;
}
Also used : Point(com.esri.core.geometry.Point)

Example 28 with Point

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();
}
Also used : GeometryUtils.wktFromJtsGeometry(com.facebook.presto.geospatial.GeometryUtils.wktFromJtsGeometry) OGCGeometry(com.esri.core.geometry.ogc.OGCGeometry) OGCGeometry.createFromEsriGeometry(com.esri.core.geometry.ogc.OGCGeometry.createFromEsriGeometry) Geometry(org.locationtech.jts.geom.Geometry) GeometryUtils.jsonFromJtsGeometry(com.facebook.presto.geospatial.GeometryUtils.jsonFromJtsGeometry) GeometryUtils.createJtsMultiPoint(com.facebook.presto.geospatial.GeometryUtils.createJtsMultiPoint) Point(com.esri.core.geometry.Point) GeometryUtils.createJtsEmptyPoint(com.facebook.presto.geospatial.GeometryUtils.createJtsEmptyPoint) GeometryUtils.createJtsPoint(com.facebook.presto.geospatial.GeometryUtils.createJtsPoint) SqlNullable(com.facebook.presto.spi.function.SqlNullable) ScalarFunction(com.facebook.presto.spi.function.ScalarFunction) Description(com.facebook.presto.spi.function.Description) SqlType(com.facebook.presto.spi.function.SqlType)

Example 29 with Point

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));
}
Also used : OGCPoint(com.esri.core.geometry.ogc.OGCPoint) Point(com.esri.core.geometry.Point) Test(org.testng.annotations.Test)

Example 30 with Point

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));
    }
}
Also used : Block(com.facebook.presto.common.block.Block) OGCPoint(com.esri.core.geometry.ogc.OGCPoint) Point(com.esri.core.geometry.Point) BlockBuilder(com.facebook.presto.common.block.BlockBuilder) Test(org.testng.annotations.Test)

Aggregations

Point (com.esri.core.geometry.Point)33 OGCPoint (com.esri.core.geometry.ogc.OGCPoint)13 OGCGeometry (com.esri.core.geometry.ogc.OGCGeometry)7 Polyline (com.esri.core.geometry.Polyline)6 Description (com.facebook.presto.spi.function.Description)6 ScalarFunction (com.facebook.presto.spi.function.ScalarFunction)6 SqlType (com.facebook.presto.spi.function.SqlType)6 Polygon (com.esri.core.geometry.Polygon)4 GeometryUtils.createJtsEmptyPoint (com.facebook.presto.geospatial.GeometryUtils.createJtsEmptyPoint)4 GeometryUtils.createJtsMultiPoint (com.facebook.presto.geospatial.GeometryUtils.createJtsMultiPoint)4 GeometryUtils.createJtsPoint (com.facebook.presto.geospatial.GeometryUtils.createJtsPoint)4 SqlNullable (com.facebook.presto.spi.function.SqlNullable)4 Test (org.testng.annotations.Test)4 Geometry (com.esri.core.geometry.Geometry)3 Line (com.esri.core.geometry.Line)3 MultiPath (com.esri.core.geometry.MultiPath)3 OGCPolygon (com.esri.core.geometry.ogc.OGCPolygon)3 BlockBuilder (com.facebook.presto.common.block.BlockBuilder)3 CartesianPoint (com.facebook.presto.geospatial.SphericalGeographyUtils.CartesianPoint)3 PrestoException (com.facebook.presto.spi.PrestoException)3