Search in sources :

Example 6 with Venue

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

the class AbstractGeoSpatialTests method nearSphere.

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

Example 7 with Venue

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

the class GeoSpatial2DSphereTests method geoNearWithMinDistance.

// DATAMONGO-1110
@Test
public void geoNearWithMinDistance() {
    NearQuery geoNear = NearQuery.near(-73, 40, Metrics.KILOMETERS).num(10).minDistance(1);
    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 8 with Venue

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

the class GeoSpatial2DTests method nearPoint.

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

Example 9 with Venue

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

the class AggregationTests method shouldSupportGeoNearQueriesForAggregationWithDistanceField.

// DATAMONGO-1127
@Test
public void shouldSupportGeoNearQueriesForAggregationWithDistanceField() {
    mongoTemplate.insert(new Venue("Penn Station", -73.99408, 40.75057));
    mongoTemplate.insert(new Venue("10gen Office", -73.99171, 40.738868));
    mongoTemplate.insert(new Venue("Flatiron Building", -73.988135, 40.741404));
    mongoTemplate.indexOps(Venue.class).ensureIndex(new GeospatialIndex("location"));
    NearQuery geoNear = NearQuery.near(-73, 40, Metrics.KILOMETERS).num(10).maxDistance(150);
    Aggregation agg = newAggregation(Aggregation.geoNear(geoNear, "distance"));
    AggregationResults<Document> result = mongoTemplate.aggregate(agg, Venue.class, Document.class);
    assertThat(result.getMappedResults(), hasSize(3));
    Document firstResult = result.getMappedResults().get(0);
    assertThat(firstResult.containsKey("distance"), is(true));
    assertThat((Double) firstResult.get("distance"), closeTo(117.620092203928, 0.00001));
}
Also used : Aggregation(org.springframework.data.mongodb.core.aggregation.Aggregation) NearQuery(org.springframework.data.mongodb.core.query.NearQuery) Venue(org.springframework.data.mongodb.core.Venue) GeospatialIndex(org.springframework.data.mongodb.core.index.GeospatialIndex) Document(org.bson.Document) Test(org.junit.Test)

Example 10 with Venue

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

the class AbstractGeoSpatialTests method withinBox.

@Test
public void withinBox() {
    Box box = new Box(new Point(-73.99756, 40.73083), new Point(-73.988135, 40.741404));
    List<Venue> venues = template.find(query(where("location").within(box)), Venue.class);
    assertThat(venues.size(), is(4));
}
Also used : Venue(org.springframework.data.mongodb.core.Venue) Box(org.springframework.data.geo.Box) Point(org.springframework.data.geo.Point) 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