Search in sources :

Example 11 with Point

use of com.esri.core.geometry.Point in project presto by prestodb.

the class SphericalGeoFunctions method computeSphericalExcess.

private static double computeSphericalExcess(Polygon polygon, int start, int end) {
    // Our calculations rely on not processing the same point twice
    if (polygon.getPoint(end - 1).equals(polygon.getPoint(start))) {
        end = end - 1;
    }
    if (end - start < 3) {
        // A path with less than 3 distinct points is not valid for calculating an area
        throw new PrestoException(INVALID_FUNCTION_ARGUMENT, "Polygon is not valid: a loop contains less then 3 vertices.");
    }
    Point point = new Point();
    // Initialize the calculator with the last point
    polygon.getPoint(end - 1, point);
    SphericalExcessCalculator calculator = new SphericalExcessCalculator(point);
    for (int i = start; i < end; i++) {
        polygon.getPoint(i, point);
        calculator.add(point);
    }
    return calculator.computeSphericalExcess();
}
Also used : PrestoException(com.facebook.presto.spi.PrestoException) CartesianPoint(com.facebook.presto.geospatial.SphericalGeographyUtils.CartesianPoint) OGCPoint(com.esri.core.geometry.ogc.OGCPoint) Point(com.esri.core.geometry.Point) CartesianPoint(com.facebook.presto.geospatial.SphericalGeographyUtils.CartesianPoint) OGCPoint(com.esri.core.geometry.ogc.OGCPoint) Point(com.esri.core.geometry.Point)

Example 12 with Point

use of com.esri.core.geometry.Point in project presto by prestodb.

the class SphericalGeoFunctions method stSphericalLength.

@SqlNullable
@Description("Returns the great-circle length in meters of a linestring or multi-linestring on Earth's surface")
@ScalarFunction("ST_Length")
@SqlType(DOUBLE)
public static Double stSphericalLength(@SqlType(SPHERICAL_GEOGRAPHY_TYPE_NAME) Slice input) {
    OGCGeometry geometry = EsriGeometrySerde.deserialize(input);
    if (geometry.isEmpty()) {
        return null;
    }
    validateSphericalType("ST_Length", geometry, EnumSet.of(LINE_STRING, MULTI_LINE_STRING));
    MultiPath lineString = (MultiPath) geometry.getEsriGeometry();
    double sum = 0;
    // sum up paths on (multi)linestring
    for (int path = 0; path < lineString.getPathCount(); path++) {
        if (lineString.getPathSize(path) < 2) {
            continue;
        }
        // sum up distances between adjacent points on this path
        int pathStart = lineString.getPathStart(path);
        Point prev = lineString.getPoint(pathStart);
        for (int i = pathStart + 1; i < lineString.getPathEnd(path); i++) {
            Point next = lineString.getPoint(i);
            sum += greatCircleDistance(prev.getY(), prev.getX(), next.getY(), next.getX());
            prev = next;
        }
    }
    return sum * 1000;
}
Also used : OGCGeometry(com.esri.core.geometry.ogc.OGCGeometry) MultiPath(com.esri.core.geometry.MultiPath) CartesianPoint(com.facebook.presto.geospatial.SphericalGeographyUtils.CartesianPoint) OGCPoint(com.esri.core.geometry.ogc.OGCPoint) Point(com.esri.core.geometry.Point) CartesianPoint(com.facebook.presto.geospatial.SphericalGeographyUtils.CartesianPoint) OGCPoint(com.esri.core.geometry.ogc.OGCPoint) Point(com.esri.core.geometry.Point) 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 13 with Point

use of com.esri.core.geometry.Point in project presto by prestodb.

the class BingTileFunctions method bingTilesAround.

@Description("Given a (longitude, latitude) point, returns the surrounding Bing tiles at the specified zoom level")
@ScalarFunction("bing_tiles_around")
@SqlType("array(" + BingTileType.NAME + ")")
public static Block bingTilesAround(@SqlType(StandardTypes.DOUBLE) double latitude, @SqlType(StandardTypes.DOUBLE) double longitude, @SqlType(StandardTypes.INTEGER) long zoomLevel) {
    checkLatitude(latitude, LATITUDE_OUT_OF_RANGE);
    checkLongitude(longitude, LONGITUDE_OUT_OF_RANGE);
    checkZoomLevel(zoomLevel);
    long mapSize = mapSize(toIntExact(zoomLevel));
    long maxTileIndex = (mapSize / TILE_PIXELS) - 1;
    int tileX = longitudeToTileX(longitude, mapSize);
    int tileY = latitudeToTileY(latitude, mapSize);
    BlockBuilder blockBuilder = BIGINT.createBlockBuilder(null, 9);
    for (int i = -1; i <= 1; i++) {
        for (int j = -1; j <= 1; j++) {
            int x = tileX + i;
            int y = tileY + j;
            if (x >= 0 && x <= maxTileIndex && y >= 0 && y <= maxTileIndex) {
                BIGINT.writeLong(blockBuilder, BingTile.fromCoordinates(x, y, toIntExact(zoomLevel)).encode());
            }
        }
    }
    return blockBuilder.build();
}
Also used : GeometryUtils.disjoint(com.facebook.presto.geospatial.GeometryUtils.disjoint) Point(com.esri.core.geometry.Point) BlockBuilder(com.facebook.presto.common.block.BlockBuilder) ScalarFunction(com.facebook.presto.spi.function.ScalarFunction) Description(com.facebook.presto.spi.function.Description) SqlType(com.facebook.presto.spi.function.SqlType)

Example 14 with Point

use of com.esri.core.geometry.Point in project presto by prestodb.

the class EsriGeometrySerde method writePoint.

private static void writePoint(DynamicSliceOutput output, OGCGeometry geometry) {
    Geometry esriGeometry = geometry.getEsriGeometry();
    verify(esriGeometry instanceof Point, "geometry is expected to be an instance of Point");
    Point point = (Point) esriGeometry;
    verify(!point.hasAttribute(VertexDescription.Semantics.Z) && !point.hasAttribute(VertexDescription.Semantics.M) && !point.hasAttribute(VertexDescription.Semantics.ID), "Only 2D points with no ID nor M attribute are supported");
    output.appendByte(GeometrySerializationType.POINT.code());
    if (!point.isEmpty()) {
        output.appendDouble(point.getX());
        output.appendDouble(point.getY());
    } else {
        output.appendDouble(NaN);
        output.appendDouble(NaN);
    }
}
Also used : OGCGeometry(com.esri.core.geometry.ogc.OGCGeometry) Geometry(com.esri.core.geometry.Geometry) OGCPoint(com.esri.core.geometry.ogc.OGCPoint) MultiPoint(com.esri.core.geometry.MultiPoint) OGCMultiPoint(com.esri.core.geometry.ogc.OGCMultiPoint) Point(com.esri.core.geometry.Point)

Example 15 with Point

use of com.esri.core.geometry.Point in project presto by prestodb.

the class EsriGeometrySerde method readPoint.

private static OGCPoint readPoint(BasicSliceInput input) {
    double x = input.readDouble();
    double y = input.readDouble();
    Point point;
    if (isNaN(x) || isNaN(y)) {
        point = new Point();
    } else {
        point = new Point(x, y);
    }
    return new OGCPoint(point, null);
}
Also used : OGCPoint(com.esri.core.geometry.ogc.OGCPoint) OGCPoint(com.esri.core.geometry.ogc.OGCPoint) MultiPoint(com.esri.core.geometry.MultiPoint) OGCMultiPoint(com.esri.core.geometry.ogc.OGCMultiPoint) Point(com.esri.core.geometry.Point)

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