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