Search in sources :

Example 1 with Venue

use of org.springframework.data.mongodb.core.Venue in project spring-data-mongodb by spring-projects.

the class AbstractGeoSpatialTests method addVenues.

protected void addVenues() {
    template.insert(new Venue("Penn Station", -73.99408, 40.75057));
    template.insert(new Venue("10gen Office", -73.99171, 40.738868));
    template.insert(new Venue("Flatiron Building", -73.988135, 40.741404));
    template.insert(new Venue("Players Club", -73.997812, 40.739128));
    template.insert(new Venue("City Bakery ", -73.992491, 40.738673));
    template.insert(new Venue("Splash Bar", -73.992491, 40.738673));
    template.insert(new Venue("Momofuku Milk Bar", -73.985839, 40.731698));
    template.insert(new Venue("Shake Shack", -73.98820, 40.74164));
    template.insert(new Venue("Penn Station", -73.99408, 40.75057));
    template.insert(new Venue("Empire State Building", -73.98602, 40.74894));
    template.insert(new Venue("Ulaanbaatar, Mongolia", 106.9154, 47.9245));
    template.insert(new Venue("Maplewood, NJ", -74.2713, 40.73137));
}
Also used : Venue(org.springframework.data.mongodb.core.Venue)

Example 2 with Venue

use of org.springframework.data.mongodb.core.Venue in project spring-data-mongodb by spring-projects.

the class AbstractGeoSpatialTests method withinCenter.

@Test
public void withinCenter() {
    Circle circle = new Circle(-73.99171, 40.738868, 0.01);
    List<Venue> venues = template.find(query(where("location").within(circle)), Venue.class);
    assertThat(venues.size(), is(7));
}
Also used : Circle(org.springframework.data.geo.Circle) Venue(org.springframework.data.mongodb.core.Venue) Test(org.junit.Test)

Example 3 with Venue

use of org.springframework.data.mongodb.core.Venue in project spring-data-mongodb by spring-projects.

the class AbstractGeoSpatialTests method geoNear.

@Test
public void geoNear() {
    NearQuery geoNear = NearQuery.near(-73, 40, Metrics.KILOMETERS).num(10).maxDistance(150);
    GeoResults<Venue> result = template.geoNear(geoNear, Venue.class);
    assertThat(result.getContent().size(), is(not(0)));
    assertThat(result.getAverageDistance().getMetric(), is((Metric) Metrics.KILOMETERS));
}
Also used : NearQuery(org.springframework.data.mongodb.core.query.NearQuery) Venue(org.springframework.data.mongodb.core.Venue) Metric(org.springframework.data.geo.Metric) Test(org.junit.Test)

Example 4 with Venue

use of org.springframework.data.mongodb.core.Venue in project spring-data-mongodb by spring-projects.

the class AbstractGeoSpatialTests method withinCenterSphere.

@Test
public void withinCenterSphere() {
    Circle circle = new Circle(-73.99171, 40.738868, 0.003712240453784);
    List<Venue> venues = template.find(query(where("location").withinSphere(circle)), Venue.class);
    assertThat(venues.size(), is(11));
}
Also used : Circle(org.springframework.data.geo.Circle) Venue(org.springframework.data.mongodb.core.Venue) Test(org.junit.Test)

Example 5 with Venue

use of org.springframework.data.mongodb.core.Venue in project spring-data-mongodb by spring-projects.

the class AbstractGeoSpatialTests method withinPolygon.

@Test
public void withinPolygon() {
    Point first = new Point(-73.99756, 40.73083);
    Point second = new Point(-73.99756, 40.741404);
    Point third = new Point(-73.988135, 40.741404);
    Point fourth = new Point(-73.988135, 40.73083);
    Polygon polygon = new Polygon(first, second, third, fourth);
    List<Venue> venues = template.find(query(where("location").within(polygon)), Venue.class);
    assertThat(venues.size(), is(4));
}
Also used : Venue(org.springframework.data.mongodb.core.Venue) Point(org.springframework.data.geo.Point) Polygon(org.springframework.data.geo.Polygon) Test(org.junit.Test)

Aggregations

Venue (org.springframework.data.mongodb.core.Venue)11 Test (org.junit.Test)10 Point (org.springframework.data.geo.Point)5 NearQuery (org.springframework.data.mongodb.core.query.NearQuery)4 Circle (org.springframework.data.geo.Circle)2 Metric (org.springframework.data.geo.Metric)2 Document (org.bson.Document)1 Box (org.springframework.data.geo.Box)1 Polygon (org.springframework.data.geo.Polygon)1 Aggregation (org.springframework.data.mongodb.core.aggregation.Aggregation)1 GeospatialIndex (org.springframework.data.mongodb.core.index.GeospatialIndex)1 Query (org.springframework.data.mongodb.core.query.Query)1