use of com.mongodb.client.model.geojson.Point in project morphia by mongodb.
the class TestGeoQueries method maxDistance.
@Test
public void maxDistance() {
// given
double latitude = 51.5286416;
double longitude = -0.1015987;
Datastore datastore = getDs();
City london = datastore.save(new City("London", new Point(new Position(latitude, longitude))));
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();
// when
List<City> cities = datastore.find(City.class).filter(near("location", new Point(new Position(latitude, longitude))).maxDistance(200000.0)).iterator().toList();
// then
assertThat(cities.size(), is(1));
assertThat(cities.get(0), is(london));
}
use of com.mongodb.client.model.geojson.Point in project morphia by mongodb.
the class TestGeoQueries method testNearNoIndex.
@Test(expectedExceptions = MongoQueryException.class)
public void testNearNoIndex() {
getDs().getCollection(Place.class).drop();
final Place place1 = new Place("place1", new double[] { 1, 1 });
getDs().save(place1);
Place found = getDs().find(Place.class).filter(near("loc", new Point(new Position(0, 0)))).iterator(new FindOptions().limit(1)).tryNext();
Assert.assertNull(found);
}
use of com.mongodb.client.model.geojson.Point in project morphia by mongodb.
the class TestGeoQueries method testGeoWithinRadiusSphere.
@Test
public void testGeoWithinRadiusSphere() {
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.Point in project morphia by mongodb.
the class AggregationTest method testGeoNearWithGeoJson.
@Test
public void testGeoNearWithGeoJson() {
// given
Point londonPoint = new Point(new Position(51.5286416, -0.1015987));
GeoCity london = new GeoCity("London", londonPoint);
getDs().save(london);
GeoCity manchester = new GeoCity("Manchester", new Point(new Position(53.4722454, -2.2235922)));
getDs().save(manchester);
GeoCity sevilla = new GeoCity("Sevilla", new Point(new Position(37.3753708, -5.9550582)));
getDs().save(sevilla);
getDs().ensureIndexes();
// when
Iterator<GeoCity> cities = getDs().aggregate(GeoCity.class).geoNear(geoNear(londonPoint).distanceField("distance").spherical(true)).execute(GeoCity.class);
// then
Assert.assertTrue(cities.hasNext());
Assert.assertEquals(london, cities.next());
Assert.assertEquals(manchester, cities.next());
Assert.assertEquals(sevilla, cities.next());
Assert.assertFalse(cities.hasNext());
}
use of com.mongodb.client.model.geojson.Point in project morphia by mongodb.
the class AggregationTest method testGeoNearWithSphericalGeometry.
@Test
public void testGeoNearWithSphericalGeometry() {
// given
double latitude = 51.5286416;
double longitude = -0.1015987;
GeoCity london = new GeoCity("London", new Point(new Position(latitude, longitude)));
getDs().save(london);
GeoCity manchester = new GeoCity("Manchester", new Point(new Position(53.4722454, -2.2235922)));
getDs().save(manchester);
GeoCity sevilla = new GeoCity("Sevilla", new Point(new Position(37.3753708, -5.9550582)));
getDs().save(sevilla);
getDs().ensureIndexes();
// when
Iterator<GeoCity> cities = getDs().aggregate(GeoCity.class).geoNear(geoNear(new double[] { latitude, longitude }).distanceField("distance").spherical(true)).execute(GeoCity.class);
// then
Assert.assertTrue(cities.hasNext());
Assert.assertEquals(london, cities.next());
Assert.assertEquals(manchester, cities.next());
Assert.assertEquals(sevilla, cities.next());
Assert.assertFalse(cities.hasNext());
}
Aggregations