Search in sources :

Example 1 with Point

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

the class Geo method lineString.

/**
 * Creates a line string from the coordinates of its points.
 *
 * <p>This is provided for backward compatibility with previous DSE versions. We recommend {@link
 * #lineString(Point, Point, Point...)} instead.
 */
@NonNull
static LineString lineString(double... coordinates) {
    if (coordinates.length % 2 != 0) {
        throw new IllegalArgumentException("lineString() must be passed an even number of arguments");
    } else if (coordinates.length < 4) {
        throw new IllegalArgumentException("lineString() must be passed at least 4 arguments (2 points)");
    }
    Point point1 = Point.fromCoordinates(coordinates[0], coordinates[1]);
    Point point2 = Point.fromCoordinates(coordinates[2], coordinates[3]);
    Point[] otherPoints = new Point[coordinates.length / 2 - 2];
    for (int i = 4; i < coordinates.length; i += 2) {
        otherPoints[i / 2 - 2] = Point.fromCoordinates(coordinates[i], coordinates[i + 1]);
    }
    return LineString.fromPoints(point1, point2, otherPoints);
}
Also used : Point(com.datastax.dse.driver.api.core.data.geometry.Point) Point(com.datastax.dse.driver.api.core.data.geometry.Point) NonNull(edu.umd.cs.findbugs.annotations.NonNull)

Example 2 with Point

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

the class DistanceSerializer method readCustomValue.

@Override
protected Distance readCustomValue(int valueLength, Buffer buffer, GraphBinaryReader context) throws IOException {
    Point p = context.readValue(buffer, Point.class, false);
    checkValueSize(GraphBinaryUtils.sizeOfDistance(p), valueLength);
    return new Distance(p, context.readValue(buffer, Double.class, false));
}
Also used : Point(com.datastax.dse.driver.api.core.data.geometry.Point) Distance(com.datastax.dse.driver.internal.core.data.geometry.Distance)

Example 3 with Point

use of com.datastax.dse.driver.api.core.data.geometry.Point 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);
}
Also used : Arrays(java.util.Arrays) INT(com.datastax.oss.driver.api.core.type.DataTypes.INT) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) LineString(com.datastax.dse.driver.api.core.data.geometry.LineString) ByteBuffer(java.nio.ByteBuffer) BIGINT(com.datastax.oss.driver.api.core.type.DataTypes.BIGINT) Point(com.datastax.dse.driver.api.core.data.geometry.Point) BigDecimal(java.math.BigDecimal) ImmutableList(com.google.common.collect.ImmutableList) CqlSession(com.datastax.oss.driver.api.core.CqlSession) Uuids(com.datastax.oss.driver.api.core.uuid.Uuids) Map(java.util.Map) LocalTime(java.time.LocalTime) BigInteger(java.math.BigInteger) DseDataTypes(com.datastax.dse.driver.api.core.type.DseDataTypes) Polygon(com.datastax.dse.driver.api.core.data.geometry.Polygon) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) Geo(com.datastax.dse.driver.api.core.graph.predicates.Geo) TupleType(com.datastax.oss.driver.api.core.type.TupleType) Test(org.junit.Test) Instant(java.time.Instant) UdtValue(com.datastax.oss.driver.api.core.data.UdtValue) Sets(com.google.common.collect.Sets) ZoneId(java.time.ZoneId) UserDefinedType(com.datastax.oss.driver.api.core.type.UserDefinedType) ChronoUnit(java.time.temporal.ChronoUnit) DataTypes.listOf(com.datastax.oss.driver.api.core.type.DataTypes.listOf) LocalDate(java.time.LocalDate) CqlDuration(com.datastax.oss.driver.api.core.data.CqlDuration) DataTypes.tupleOf(com.datastax.oss.driver.api.core.type.DataTypes.tupleOf) TEXT(com.datastax.oss.driver.api.core.type.DataTypes.TEXT) TupleType(com.datastax.oss.driver.api.core.type.TupleType) LineString(com.datastax.dse.driver.api.core.data.geometry.LineString) CqlSession(com.datastax.oss.driver.api.core.CqlSession) ImmutableMap(com.google.common.collect.ImmutableMap) Point(com.datastax.dse.driver.api.core.data.geometry.Point) Test(org.junit.Test)

Example 4 with Point

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

the class DefaultPointTest method should_produce_same_hashCode_for_equal_objects.

@Test
public void should_produce_same_hashCode_for_equal_objects() {
    Point point1 = new DefaultPoint(10, 20);
    Point point2 = Point.fromWellKnownText("POINT (10 20)");
    assertThat(point1).isEqualTo(point2);
    assertThat(point1.hashCode()).isEqualTo(point2.hashCode());
}
Also used : Point(com.datastax.dse.driver.api.core.data.geometry.Point) OGCPoint(com.esri.core.geometry.ogc.OGCPoint) Test(org.junit.Test)

Example 5 with Point

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

the class DefaultPolygon method addPath.

private static void addPath(com.esri.core.geometry.Polygon polygon, Point p1, Point p2, Point p3, Point[] pn) {
    polygon.startPath(toEsri(p1));
    polygon.lineTo(toEsri(p2));
    polygon.lineTo(toEsri(p3));
    for (Point p : pn) {
        polygon.lineTo(toEsri(p));
    }
}
Also used : Point(com.datastax.dse.driver.api.core.data.geometry.Point)

Aggregations

Point (com.datastax.dse.driver.api.core.data.geometry.Point)7 NonNull (edu.umd.cs.findbugs.annotations.NonNull)2 Test (org.junit.Test)2 LineString (com.datastax.dse.driver.api.core.data.geometry.LineString)1 Polygon (com.datastax.dse.driver.api.core.data.geometry.Polygon)1 Geo (com.datastax.dse.driver.api.core.graph.predicates.Geo)1 DseDataTypes (com.datastax.dse.driver.api.core.type.DseDataTypes)1 Distance (com.datastax.dse.driver.internal.core.data.geometry.Distance)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 GeoMailboxMessage (com.datastax.oss.driver.api.osgi.service.geo.GeoMailboxMessage)1