Search in sources :

Example 6 with Point

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

the class Geo method polygon.

/**
 * Creates a polygon from the coordinates of its points.
 *
 * <p>This is provided for backward compatibility with previous DSE versions. We recommend {@link
 * #polygon(Point, Point, Point, Point...)} instead.
 */
@NonNull
static Polygon polygon(double... coordinates) {
    if (coordinates.length % 2 != 0) {
        throw new IllegalArgumentException("polygon() must be passed an even number of arguments");
    } else if (coordinates.length < 6) {
        throw new IllegalArgumentException("polygon() must be passed at least 6 arguments (3 points)");
    }
    Point point1 = Point.fromCoordinates(coordinates[0], coordinates[1]);
    Point point2 = Point.fromCoordinates(coordinates[2], coordinates[3]);
    Point point3 = Point.fromCoordinates(coordinates[4], coordinates[5]);
    Point[] otherPoints = new Point[coordinates.length / 2 - 3];
    for (int i = 6; i < coordinates.length; i += 2) {
        otherPoints[i / 2 - 3] = Point.fromCoordinates(coordinates[i], coordinates[i + 1]);
    }
    return Polygon.fromPoints(point1, point2, point3, 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 7 with Point

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

the class GeoServiceChecks method checkServiceGeo.

public static void checkServiceGeo(GeoMailboxService service) throws Exception {
    // Insert some data into mailbox for a particular user.
    String recipient = "user@datastax.com";
    try {
        List<GeoMailboxMessage> insertedMessages = new ArrayList<>();
        for (int i = 0; i < 30; i++) {
            Point location = Point.fromCoordinates(i, i);
            GeoMailboxMessage message = new GeoMailboxMessage(recipient, location, "sender" + i, "body" + i);
            insertedMessages.add(message);
            service.sendGeoMessage(message);
        }
        Iterable<GeoMailboxMessage> retrievedMessages = service.getGeoMessages(recipient);
        assertThat(retrievedMessages).containsExactlyInAnyOrderElementsOf(insertedMessages);
    } finally {
        service.clearGeoMailbox(recipient);
    }
}
Also used : ArrayList(java.util.ArrayList) Point(com.datastax.dse.driver.api.core.data.geometry.Point) GeoMailboxMessage(com.datastax.oss.driver.api.osgi.service.geo.GeoMailboxMessage) 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