Search in sources :

Example 11 with Position

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

the class TestGeoQueries method geoIntersects.

@Test
public void geoIntersects() {
    // given
    City manchester = new City("Manchester", new Point(new Position(53.4722454, -2.2235922)));
    getDs().save(manchester);
    getDs().save(new City("London", new Point(new Position(51.5286416, -0.1015987))));
    City sevilla = getDs().save(new City("Sevilla", new Point(new Position(37.4057731, -5.966287))));
    getDs().ensureIndexes();
    // when
    List<City> matchingCity = getDs().find(City.class).filter(Filters.geoIntersects("location", new Polygon(asList(new Position(37.40759155713022, -5.964911067858338), new Position(37.40341208875179, -5.9643941558897495), new Position(37.40297396667302, -5.970452763140202), new Position(37.40759155713022, -5.964911067858338))))).iterator().toList();
    // then
    assertThat(matchingCity.size(), is(1));
    assertThat(matchingCity.get(0), is(sevilla));
}
Also used : Position(com.mongodb.client.model.geojson.Position) Point(com.mongodb.client.model.geojson.Point) Polygon(com.mongodb.client.model.geojson.Polygon) Test(org.testng.annotations.Test)

Example 12 with Position

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

the class TestGeoQueries method testWithinRadius.

@Test
public void testWithinRadius() {
    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)

Example 13 with Position

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

the class TestGeoQueries method testGeoWithinOutsideBox.

@Test
public void testGeoWithinOutsideBox() {
    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(.4, .5)))).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 14 with Position

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

the class TestGeoQueries method testGeoWithinRadius2.

@Test
public void testGeoWithinRadius2() {
    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.5, 0.5)), 0.77)).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 15 with Position

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

the class TestGeoQueries method testWithinOutsideRadius.

@Test
public void testWithinOutsideRadius() {
    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(2, 2)), 0.4)).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)

Aggregations

Position (com.mongodb.client.model.geojson.Position)35 Point (com.mongodb.client.model.geojson.Point)23 Test (org.testng.annotations.Test)23 FindOptions (dev.morphia.query.FindOptions)16 CodecConfigurationException (org.bson.codecs.configuration.CodecConfigurationException)5 CoordinateReferenceSystem (com.mongodb.client.model.geojson.CoordinateReferenceSystem)3 LineString (com.mongodb.client.model.geojson.LineString)3 MultiLineString (com.mongodb.client.model.geojson.MultiLineString)3 NamedCoordinateReferenceSystem (com.mongodb.client.model.geojson.NamedCoordinateReferenceSystem)3 PolygonCoordinates (com.mongodb.client.model.geojson.PolygonCoordinates)3 MultiPoint (com.mongodb.client.model.geojson.MultiPoint)2 MultiPolygon (com.mongodb.client.model.geojson.MultiPolygon)2 Polygon (com.mongodb.client.model.geojson.Polygon)2 Datastore (dev.morphia.Datastore)2 GeoCity (dev.morphia.test.models.geo.GeoCity)2 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 List (java.util.List)1