Search in sources :

Example 1 with Polygon

use of com.datastax.dse.driver.api.core.data.geometry.Polygon in project java-driver by datastax.

the class DistanceTest method should_not_contain_polygon.

@Test
public void should_not_contain_polygon() {
    Polygon polygon = Polygon.fromPoints(Point.fromCoordinates(3, 1), Point.fromCoordinates(1, 2), Point.fromCoordinates(2, 4), Point.fromCoordinates(10, 4));
    // final point falls outside of distance at x axis.
    assertThat(distance.contains(polygon)).isFalse();
}
Also used : Polygon(com.datastax.dse.driver.api.core.data.geometry.Polygon) Test(org.junit.Test)

Example 2 with Polygon

use of com.datastax.dse.driver.api.core.data.geometry.Polygon in project java-driver by datastax.

the class DistanceTest method should_contain_polygon.

@Test
public void should_contain_polygon() {
    Polygon polygon = Polygon.fromPoints(Point.fromCoordinates(3, 1), Point.fromCoordinates(1, 2), Point.fromCoordinates(2, 4), Point.fromCoordinates(4, 4));
    assertThat(distance.contains(polygon)).isTrue();
}
Also used : Polygon(com.datastax.dse.driver.api.core.data.geometry.Polygon) Test(org.junit.Test)

Example 3 with Polygon

use of com.datastax.dse.driver.api.core.data.geometry.Polygon in project java-driver by datastax.

the class GeoTest method should_build_polygon_from_coordinates.

@Test
public void should_build_polygon_from_coordinates() {
    Polygon polygon = Geo.polygon(1, 2, 3, 4, 5, 6, 7, 8);
    assertThat(polygon.getExteriorRing()).hasSize(4).contains(Point.fromCoordinates(1, 2)).contains(Point.fromCoordinates(3, 4)).contains(Point.fromCoordinates(5, 6)).contains(Point.fromCoordinates(7, 8));
    assertThat(polygon.getInteriorRings()).isEmpty();
}
Also used : Polygon(com.datastax.dse.driver.api.core.data.geometry.Polygon) Test(org.junit.Test)

Example 4 with Polygon

use of com.datastax.dse.driver.api.core.data.geometry.Polygon in project java-driver by datastax.

the class DefaultPolygonTest method should_expose_rings.

@Test
public void should_expose_rings() {
    assertThat(polygon.getExteriorRing()).containsOnly(Point.fromCoordinates(30, 10), Point.fromCoordinates(10, 20), Point.fromCoordinates(20, 40), Point.fromCoordinates(40, 40));
    assertThat(polygon.getInteriorRings().isEmpty()).isTrue();
    Polygon fromWkt = Polygon.fromWellKnownText(wkt);
    assertThat(fromWkt.getExteriorRing()).containsOnly(Point.fromCoordinates(30, 10), Point.fromCoordinates(10, 20), Point.fromCoordinates(20, 40), Point.fromCoordinates(40, 40));
    assertThat(fromWkt.getInteriorRings().isEmpty()).isTrue();
    Polygon complex = Polygon.builder().addRing(Point.fromCoordinates(0, 0), Point.fromCoordinates(0, 3), Point.fromCoordinates(5, 3), Point.fromCoordinates(5, 0)).addRing(Point.fromCoordinates(1, 1), Point.fromCoordinates(1, 2), Point.fromCoordinates(2, 2), Point.fromCoordinates(2, 1)).addRing(Point.fromCoordinates(3, 1), Point.fromCoordinates(3, 2), Point.fromCoordinates(4, 2), Point.fromCoordinates(4, 1)).build();
    assertThat(complex.getExteriorRing()).containsOnly(Point.fromCoordinates(0, 0), Point.fromCoordinates(0, 3), Point.fromCoordinates(5, 3), Point.fromCoordinates(5, 0));
    assertThat(complex.getInteriorRings()).hasSize(2);
    assertThat(complex.getInteriorRings().get(0)).containsOnly(Point.fromCoordinates(1, 1), Point.fromCoordinates(1, 2), Point.fromCoordinates(2, 2), Point.fromCoordinates(2, 1));
    assertThat(complex.getInteriorRings().get(1)).containsOnly(Point.fromCoordinates(3, 1), Point.fromCoordinates(3, 2), Point.fromCoordinates(4, 2), Point.fromCoordinates(4, 1));
    Polygon complexFromWkt = Polygon.fromWellKnownText("POLYGON ((0 0, 5 0, 5 3, 0 3, 0 0), (1 1, 1 2, 2 2, 2 1, 1 1), (3 1, 3 2, 4 2, 4 1, 3 1))");
    assertThat(complexFromWkt.getExteriorRing()).containsOnly(Point.fromCoordinates(0, 0), Point.fromCoordinates(0, 3), Point.fromCoordinates(5, 3), Point.fromCoordinates(5, 0));
    assertThat(complexFromWkt.getInteriorRings()).hasSize(2);
    assertThat(complexFromWkt.getInteriorRings().get(0)).containsOnly(Point.fromCoordinates(1, 1), Point.fromCoordinates(1, 2), Point.fromCoordinates(2, 2), Point.fromCoordinates(2, 1));
    assertThat(complexFromWkt.getInteriorRings().get(1)).containsOnly(Point.fromCoordinates(3, 1), Point.fromCoordinates(3, 2), Point.fromCoordinates(4, 2), Point.fromCoordinates(4, 1));
}
Also used : Polygon(com.datastax.dse.driver.api.core.data.geometry.Polygon) OGCPolygon(com.esri.core.geometry.ogc.OGCPolygon) Test(org.junit.Test)

Example 5 with Polygon

use of com.datastax.dse.driver.api.core.data.geometry.Polygon in project java-driver by datastax.

the class DefaultPolygonTest method should_accept_empty_shape.

@Test
public void should_accept_empty_shape() throws Exception {
    Polygon polygon = Polygon.fromWellKnownText("POLYGON EMPTY");
    assertThat(polygon.getExteriorRing()).isEmpty();
    assertThat(((DefaultPolygon) polygon).getOgcGeometry().isEmpty()).isTrue();
}
Also used : Polygon(com.datastax.dse.driver.api.core.data.geometry.Polygon) OGCPolygon(com.esri.core.geometry.ogc.OGCPolygon) Test(org.junit.Test)

Aggregations

Polygon (com.datastax.dse.driver.api.core.data.geometry.Polygon)10 Test (org.junit.Test)10 OGCPolygon (com.esri.core.geometry.ogc.OGCPolygon)6 LineString (com.datastax.dse.driver.api.core.data.geometry.LineString)1 Point (com.datastax.dse.driver.api.core.data.geometry.Point)1 Geo (com.datastax.dse.driver.api.core.graph.predicates.Geo)1 DseDataTypes (com.datastax.dse.driver.api.core.type.DseDataTypes)1 CqlSession (com.datastax.oss.driver.api.core.CqlSession)1 CqlDuration (com.datastax.oss.driver.api.core.data.CqlDuration)1 UdtValue (com.datastax.oss.driver.api.core.data.UdtValue)1 BIGINT (com.datastax.oss.driver.api.core.type.DataTypes.BIGINT)1 INT (com.datastax.oss.driver.api.core.type.DataTypes.INT)1 TEXT (com.datastax.oss.driver.api.core.type.DataTypes.TEXT)1 DataTypes.listOf (com.datastax.oss.driver.api.core.type.DataTypes.listOf)1 DataTypes.tupleOf (com.datastax.oss.driver.api.core.type.DataTypes.tupleOf)1 TupleType (com.datastax.oss.driver.api.core.type.TupleType)1 UserDefinedType (com.datastax.oss.driver.api.core.type.UserDefinedType)1 Uuids (com.datastax.oss.driver.api.core.uuid.Uuids)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1