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