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();
}
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;
}
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();
}
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);
}
}
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);
}
Aggregations