use of com.mongodb.client.model.geojson.Position in project morphia by mongodb.
the class TestGeoQueries method minDistance.
@Test
public void minDistance() {
// given
Datastore datastore = getDs();
City london = new City("London", new Point(new Position(51.5286416, -0.1015987)));
datastore.save(london);
datastore.save(List.of(new City("Manchester", new Point(new Position(53.4722454, -2.2235922))), new City("Sevilla", new Point(new Position(37.3753708, -5.9550582)))));
getDs().ensureIndexes();
final Point searchPoint = new Point(new Position(50, 0.1278));
assertThat(datastore.find(City.class).filter(near("location", searchPoint).maxDistance(200000D).minDistance(195000D)).iterator().toList().size(), is(0));
assertThat(datastore.find(City.class).filter(nearSphere("location", searchPoint).maxDistance(200000D).minDistance(195000D)).iterator().toList().size(), is(0));
}
use of com.mongodb.client.model.geojson.Position in project morphia by mongodb.
the class TestGeoQueries method testWithinRadiusSphere.
@Test
public void testWithinRadiusSphere() {
final Place place1 = new Place("place1", new double[] { 1, 1 });
getDs().save(place1);
final Place found = getDs().find(Place.class).filter(centerSphere("loc", new Point(new Position(0, 1)), 1)).iterator(new FindOptions().limit(1)).next();
Assert.assertNotNull(found);
}
use of com.mongodb.client.model.geojson.Position in project morphia by mongodb.
the class TestIndexes method shouldErrorWhenCreatingA2dIndexOnGeoJson.
@Test(expectedExceptions = MongoCommandException.class)
public void shouldErrorWhenCreatingA2dIndexOnGeoJson() {
// given
Place2D pointB = new Place2D(new Point(new Position(3.1, 7.5)), "Point B");
getDs().save(pointB);
// when
getDs().ensureIndexes();
// "location object expected, location array not in correct format", code : 13654
}
use of com.mongodb.client.model.geojson.Position in project spring-data-mongodb by spring-projects.
the class MongoTemplateMappingTests method writesAndReadsEntityWithNativeMongoGeoJsonTypesCorrectly.
// DATAMONGO-2357
@Test
public void writesAndReadsEntityWithNativeMongoGeoJsonTypesCorrectly() {
WithMongoGeoJson source = new WithMongoGeoJson();
source.id = "id-2";
source.multiPolygon = new MultiPolygon(Arrays.asList(new PolygonCoordinates(Arrays.asList(new Position(0, 0), new Position(0, 1), new Position(1, 1), new Position(1, 0), new Position(0, 0)))));
template1.save(source);
assertThat(template1.findOne(query(where("id").is(source.id)), WithMongoGeoJson.class)).isEqualTo(source);
}
use of com.mongodb.client.model.geojson.Position in project mongo-java-driver by mongodb.
the class GeometryCodecHelper method encodeLinearRing.
private static void encodeLinearRing(final List<Position> ring, final BsonWriter writer) {
writer.writeStartArray();
for (Position position : ring) {
encodePosition(writer, position);
}
writer.writeEndArray();
}
Aggregations