Search in sources :

Example 31 with Point

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

the class TestSphericalGeoFunctions method testArea.

@Test
public void testArea() throws IOException {
    // Empty polygon
    assertFunction("ST_Area(to_spherical_geography(ST_GeometryFromText('POLYGON EMPTY')))", DOUBLE, null);
    // Invalid data type (point)
    assertInvalidFunction("ST_Area(to_spherical_geography(ST_GeometryFromText('POINT (0 1)')))", "When applied to SphericalGeography inputs, ST_Area only supports POLYGON or MULTI_POLYGON. Input type is: POINT");
    // Invalid Polygon (duplicated point)
    assertInvalidFunction("ST_Area(to_spherical_geography(ST_GeometryFromText('POLYGON((0 0, 0 1, 1 1, 1 1, 1 0, 0 0))')))", "Polygon is not valid: it has two identical consecutive vertices");
    // A polygon around the North Pole
    assertArea("POLYGON((-135 85, -45 85, 45 85, 135 85, -135 85))", 619.00E9);
    assertArea("POLYGON((0 0, 0 1, 1 1, 1 0, 0 0))", 123.64E8);
    assertArea("POLYGON((-122.150124 37.486095, -122.149201 37.486606,  -122.145725 37.486580, -122.145923 37.483961, -122.149324 37.482480,  -122.150837 37.483238,  -122.150901 37.485392, -122.150124 37.486095))", 163290.93943446054);
    double angleOfOneKm = 0.008993201943349;
    assertArea(format("POLYGON((0 0, %.15f 0, %.15f %.15f, 0 %.15f, 0 0))", angleOfOneKm, angleOfOneKm, angleOfOneKm, angleOfOneKm), 1E6);
    // 1/4th of an hemisphere, ie 1/8th of the planet, should be close to 4PiR2/8 = 637.58E11
    assertArea("POLYGON((90 0, 0 0, 0 90, 90 0))", 637.58E11);
    // A Polygon with a large hole
    assertArea("POLYGON((90 0, 0 0, 0 90, 90 0), (89 1, 1 1, 1 89, 89 1))", 348.04E10);
    Path geometryPath = Paths.get(TestSphericalGeoFunctions.class.getClassLoader().getResource("us-states.tsv").getPath());
    Map<String, String> stateGeometries = Files.lines(geometryPath).map(line -> line.split("\t")).collect(Collectors.toMap(parts -> parts[0], parts -> parts[1]));
    Path areaPath = Paths.get(TestSphericalGeoFunctions.class.getClassLoader().getResource("us-state-areas.tsv").getPath());
    Map<String, Double> stateAreas = Files.lines(areaPath).map(line -> line.split("\t")).filter(parts -> parts.length >= 2).collect(Collectors.toMap(parts -> parts[0], parts -> Double.valueOf(parts[1])));
    for (String state : stateGeometries.keySet()) {
        assertArea(stateGeometries.get(state), stateAreas.get(state));
    }
}
Also used : Path(java.nio.file.Path) BlockBuilder(com.facebook.presto.common.block.BlockBuilder) SPHERICAL_GEOGRAPHY(com.facebook.presto.plugin.geospatial.SphericalGeographyType.SPHERICAL_GEOGRAPHY) Files(java.nio.file.Files) DOUBLE(com.facebook.presto.common.type.DoubleType.DOUBLE) AbstractTestFunctions(com.facebook.presto.operator.scalar.AbstractTestFunctions) BeforeClass(org.testng.annotations.BeforeClass) VARCHAR(com.facebook.presto.common.type.VarcharType.VARCHAR) Assert.assertEquals(org.testng.Assert.assertEquals) Test(org.testng.annotations.Test) IOException(java.io.IOException) SphericalGeoFunctions.toSphericalGeography(com.facebook.presto.plugin.geospatial.SphericalGeoFunctions.toSphericalGeography) Collectors(java.util.stream.Collectors) FunctionExtractor.extractFunctions(com.facebook.presto.metadata.FunctionExtractor.extractFunctions) String.format(java.lang.String.format) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) Paths(java.nio.file.Paths) OGCPoint(com.esri.core.geometry.ogc.OGCPoint) Map(java.util.Map) Slices.utf8Slice(io.airlift.slice.Slices.utf8Slice) Point(com.esri.core.geometry.Point) Block(com.facebook.presto.common.block.Block) Path(java.nio.file.Path) Type(com.facebook.presto.common.type.Type) Test(org.testng.annotations.Test)

Example 32 with Point

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

the class TestGeoFunctions method testSTEnvelopeAsPts.

@Test
public void testSTEnvelopeAsPts() {
    assertEnvelopeAsPts("MULTIPOINT (1 2, 2 4, 3 6, 4 8)", new Point(1, 2), new Point(4, 8));
    assertFunction("ST_EnvelopeAsPts(ST_GeometryFromText('LINESTRING EMPTY'))", new ArrayType(GEOMETRY), null);
    assertEnvelopeAsPts("LINESTRING (1 1, 2 2, 1 3)", new Point(1, 1), new Point(2, 3));
    assertEnvelopeAsPts("LINESTRING (8 4, 5 7)", new Point(5, 4), new Point(8, 7));
    assertEnvelopeAsPts("MULTILINESTRING ((1 1, 5 1), (2 4, 4 4))", new Point(1, 1), new Point(5, 4));
    assertEnvelopeAsPts("POLYGON ((1 1, 4 1, 1 4, 1 1))", new Point(1, 1), new Point(4, 4));
    assertEnvelopeAsPts("MULTIPOLYGON (((1 1, 1 3, 3 3, 3 1, 1 1)), ((0 0, 0 2, 2 2, 2 0, 0 0)))", new Point(0, 0), new Point(3, 3));
    assertEnvelopeAsPts("GEOMETRYCOLLECTION (POINT (5 1), LINESTRING (3 4, 4 4))", new Point(3, 1), new Point(5, 4));
    assertEnvelopeAsPts("POINT (1 2)", new Point(1, 2), new Point(1, 2));
}
Also used : ArrayType(com.facebook.presto.common.type.ArrayType) OGCPoint(com.esri.core.geometry.ogc.OGCPoint) Point(com.esri.core.geometry.Point) Test(org.testng.annotations.Test)

Example 33 with Point

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

the class GeoFunctions method stX.

@SqlNullable
@Description("Return the X coordinate of the point")
@ScalarFunction("ST_X")
@SqlType(DOUBLE)
public static Double stX(@SqlType(GEOMETRY_TYPE_NAME) Slice input) {
    Geometry geometry = deserialize(input);
    validateType("ST_X", geometry, EnumSet.of(POINT));
    if (geometry.isEmpty()) {
        return null;
    }
    return ((org.locationtech.jts.geom.Point) geometry).getX();
}
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)

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