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));
}
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));
}
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));
}
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));
}
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));
}
Aggregations