use of com.datastax.dse.driver.api.core.data.geometry.Polygon in project java-driver by datastax.
the class CoreGraphDataTypeITBase method should_create_and_retrieve_correct_data_with_types.
@Test
public void should_create_and_retrieve_correct_data_with_types() {
CqlSession session = session();
// use CQL to create type for now because DSP-17567 is not in yet, so this is more stable
session.execute(String.format("CREATE TYPE %s.udt_graphbinary(simple text, complex tuple<int, text>, missing text)", graphName()));
session.execute(String.format("CREATE TYPE %s.udt_graphbinarygeo(point 'PointType', line 'LineStringType', poly 'PolygonType')", graphName()));
ImmutableMap.Builder<String, Object> properties = ImmutableMap.<String, Object>builder().put("Ascii", "test").put("Bigint", 5L).put("Boolean", true).put("Date", LocalDate.of(2007, 7, 7)).put("Decimal", BigDecimal.valueOf(2.3)).put("Double", 4.5d).put("Float", 4.8f).put("Int", 45).put("Smallint", (short) 1).put("Text", "test").put("Time", LocalTime.now(ZoneId.systemDefault())).put("Timeuuid", Uuids.timeBased()).put("Timestamp", Instant.now().truncatedTo(ChronoUnit.MILLIS)).put("Uuid", java.util.UUID.randomUUID()).put("Varint", BigInteger.valueOf(3234)).put("Blob", ByteBuffer.wrap(new byte[] { 1, 2, 3 })).put("Tinyint", (byte) 38).put("listOf(Int)", Arrays.asList(2, 3, 4)).put("setOf(Int)", Sets.newHashSet(2, 3, 4)).put("mapOf(Int, Text)", ImmutableMap.of(2, "two", 4, "four")).put("Duration", CqlDuration.newInstance(1, 2, 3)).put("LineString", Geo.lineString(1, 2, 3, 4, 5, 6)).put("Point", Geo.point(3, 4)).put("Polygon", Geo.polygon(Geo.point(3, 4), Geo.point(5, 4), Geo.point(6, 6))).put("tupleOf(Int, Text)", tupleOf(INT, TEXT).newValue(5, "Bar")).put("typeOf('udt_graphbinary')", session.getMetadata().getKeyspace(graphName()).flatMap(keyspace -> keyspace.getUserDefinedType("udt_graphbinary")).orElseThrow(IllegalStateException::new).newValue("some text", tupleOf(INT, TEXT).newValue(5, "Bar"), "some missing text")).put("typeOf('udt_graphbinarygeo')", session.getMetadata().getKeyspace(graphName()).flatMap(keyspaceMetadata -> keyspaceMetadata.getUserDefinedType("udt_graphbinarygeo")).orElseThrow(IllegalStateException::new).newValue(Point.fromCoordinates(3.3, 4.4), LineString.fromPoints(Point.fromCoordinates(1, 1), Point.fromCoordinates(2, 2), Point.fromCoordinates(3, 3)), Polygon.fromPoints(Point.fromCoordinates(3, 4), Point.fromCoordinates(5, 4), Point.fromCoordinates(6, 6))));
TupleType tuple = tupleOf(DseDataTypes.POINT, DseDataTypes.LINE_STRING, DseDataTypes.POLYGON);
tuple.attach(session.getContext());
properties.put("tupleOf(Point, LineString, Polygon)", tuple.newValue(Point.fromCoordinates(3.3, 4.4), LineString.fromPoints(Point.fromCoordinates(1, 1), Point.fromCoordinates(2, 2), Point.fromCoordinates(3, 3)), Polygon.fromPoints(Point.fromCoordinates(3, 4), Point.fromCoordinates(5, 4), Point.fromCoordinates(6, 6))));
int vertexID = 1;
String vertexLabel = "graphBinaryAllTypes";
runTest(properties.build(), vertexLabel, vertexID);
}
use of com.datastax.dse.driver.api.core.data.geometry.Polygon in project java-driver by datastax.
the class DefaultPolygonTest method should_build_with_constructor_without_checking_orientation.
@Test
public void should_build_with_constructor_without_checking_orientation() {
// By default, OGC requires outer rings to be clockwise and inner rings to be counterclockwise.
// We disable that in our constructors.
// This polygon has a single outer ring that is counterclockwise.
Polygon polygon = Polygon.fromPoints(Point.fromCoordinates(5, 0), Point.fromCoordinates(5, 3), Point.fromCoordinates(0, 3), Point.fromCoordinates(0, 0));
assertThat(polygon.asWellKnownText()).isEqualTo("POLYGON ((0 0, 5 0, 5 3, 0 3, 0 0))");
}
use of com.datastax.dse.driver.api.core.data.geometry.Polygon in project java-driver by datastax.
the class DefaultPolygonTest method should_build_complex_polygon_with_builder.
@Test
public void should_build_complex_polygon_with_builder() {
Polygon polygon = 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(polygon.asWellKnownText()).isEqualTo("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))");
}
use of com.datastax.dse.driver.api.core.data.geometry.Polygon in project java-driver by datastax.
the class DefaultPolygonTest method should_produce_same_hashCode_for_equal_objects.
@Test
public void should_produce_same_hashCode_for_equal_objects() {
Polygon polygon1 = Polygon.fromPoints(Point.fromCoordinates(30, 10), Point.fromCoordinates(10, 20), Point.fromCoordinates(20, 40), Point.fromCoordinates(40, 40));
Polygon polygon2 = Polygon.fromWellKnownText(wkt);
assertThat(polygon1).isEqualTo(polygon2);
assertThat(polygon1.hashCode()).isEqualTo(polygon2.hashCode());
}
use of com.datastax.dse.driver.api.core.data.geometry.Polygon in project java-driver by datastax.
the class DefaultPolygonTest method should_not_contain_shapes_in_interior_hole.
@Test
public void should_not_contain_shapes_in_interior_hole() {
Polygon complex = Polygon.builder().addRing(Point.fromCoordinates(0, 0), Point.fromCoordinates(30, 0), Point.fromCoordinates(30, 30), Point.fromCoordinates(0, 30)).addRing(Point.fromCoordinates(10, 10), Point.fromCoordinates(20, 10), Point.fromCoordinates(20, 20), Point.fromCoordinates(10, 20)).build();
assertThat(complex.contains(Point.fromCoordinates(15, 15))).isFalse();
}
Aggregations