Search in sources :

Example 16 with Point

use of com.mongodb.client.model.geojson.Point in project morphia by mongodb.

the class TestGeoQueries method testGeoWithinPolygon2.

@Test
public void testGeoWithinPolygon2() {
    final Place place1 = new Place("place1", new double[] { 10, 1 });
    getDs().save(place1);
    final Place found = getDs().find(Place.class).filter(polygon("loc", new Point(new Position(0, 0)), new Point(new Position(0, 5)), new Point(new Position(2, 3)), new Point(new Position(2, 0)))).iterator(new FindOptions().limit(1)).tryNext();
    Assert.assertNull(found);
}
Also used : FindOptions(dev.morphia.query.FindOptions) Position(com.mongodb.client.model.geojson.Position) Point(com.mongodb.client.model.geojson.Point) Test(org.testng.annotations.Test)

Example 17 with Point

use of com.mongodb.client.model.geojson.Point in project morphia by mongodb.

the class TestGeoQueries method testNear.

@Test
public void testNear() {
    final Place place1 = new Place("place1", new double[] { 1, 1 });
    getDs().save(place1);
    final Place found = getDs().find(Place.class).filter(near("loc", new Point(new Position(0, 0)))).iterator(new FindOptions().limit(1)).next();
    Assert.assertNotNull(found);
}
Also used : FindOptions(dev.morphia.query.FindOptions) Position(com.mongodb.client.model.geojson.Position) Point(com.mongodb.client.model.geojson.Point) Test(org.testng.annotations.Test)

Example 18 with Point

use of com.mongodb.client.model.geojson.Point in project morphia by mongodb.

the class TestGeoQueries method testNearMaxDistance.

@Test
public void testNearMaxDistance() {
    final Place place1 = new Place("place1", new double[] { 1, 1 });
    getDs().save(place1);
    FindOptions options = new FindOptions().logQuery().limit(1);
    Query<Place> query = getDs().find(Place.class).filter(near("loc", new Point(new Position(1, 1))).maxDistance(2.0));
    Assert.assertNotNull(query.iterator(options).tryNext(), query.getLoggedQuery());
    query = getDs().find(Place.class).filter(near("loc", new Point(new Position(0, 0))).maxDistance(1.0));
    Assert.assertNull(query.first(options), query.getLoggedQuery());
}
Also used : FindOptions(dev.morphia.query.FindOptions) Position(com.mongodb.client.model.geojson.Position) Point(com.mongodb.client.model.geojson.Point) Test(org.testng.annotations.Test)

Example 19 with Point

use of com.mongodb.client.model.geojson.Point in project morphia by mongodb.

the class TestGeoQueries method testGeoWithinBox.

@Test
public void testGeoWithinBox() {
    final Place place1 = new Place("place1", new double[] { 1, 1 });
    getDs().save(place1);
    final Place found = getDs().find(Place.class).filter(box("loc", new Point(new Position(0, 0)), new Point(new Position(2, 2)))).iterator(new FindOptions().limit(1)).next();
    Assert.assertNotNull(found);
}
Also used : FindOptions(dev.morphia.query.FindOptions) Position(com.mongodb.client.model.geojson.Position) Point(com.mongodb.client.model.geojson.Point) Test(org.testng.annotations.Test)

Example 20 with Point

use of com.mongodb.client.model.geojson.Point in project morphia by mongodb.

the class TestGeoQueries method testGeoWithinRadius.

@Test
public void testGeoWithinRadius() {
    final Place place1 = new Place("place1", new double[] { 1, 1 });
    getDs().save(place1);
    final Place found = getDs().find(Place.class).filter(center("loc", new Point(new Position(0, 1)), 1.1)).iterator(new FindOptions().limit(1)).next();
    Assert.assertNotNull(found);
}
Also used : FindOptions(dev.morphia.query.FindOptions) Position(com.mongodb.client.model.geojson.Position) Point(com.mongodb.client.model.geojson.Point) Test(org.testng.annotations.Test)

Aggregations

Point (com.mongodb.client.model.geojson.Point)26 Position (com.mongodb.client.model.geojson.Position)23 Test (org.testng.annotations.Test)22 FindOptions (dev.morphia.query.FindOptions)16 LineString (com.mongodb.client.model.geojson.LineString)2 MultiLineString (com.mongodb.client.model.geojson.MultiLineString)2 MultiPoint (com.mongodb.client.model.geojson.MultiPoint)2 Polygon (com.mongodb.client.model.geojson.Polygon)2 Datastore (dev.morphia.Datastore)2 GeoCity (dev.morphia.test.models.geo.GeoCity)2 CodecConfigurationException (org.bson.codecs.configuration.CodecConfigurationException)2 CoordinateReferenceSystem (com.mongodb.client.model.geojson.CoordinateReferenceSystem)1 GeometryCollection (com.mongodb.client.model.geojson.GeometryCollection)1 MultiPolygon (com.mongodb.client.model.geojson.MultiPolygon)1 NamedCoordinateReferenceSystem (com.mongodb.client.model.geojson.NamedCoordinateReferenceSystem)1