Search in sources :

Example 1 with Point

use of org.springframework.data.geo.Point in project spring-data-mongodb by spring-projects.

the class MongoOperationsUnitTests method geoNearRejectsNullEntityClassIfCollectionGiven.

// DATAMONGO-341
@Test
public void geoNearRejectsNullEntityClassIfCollectionGiven() {
    final NearQuery query = NearQuery.near(new Point(10, 20));
    new Execution() {

        @Override
        public void doWith(MongoOperations operations) {
            operations.geoNear(query, null, "collection");
        }
    }.assertDataAccessException();
}
Also used : NearQuery(org.springframework.data.mongodb.core.query.NearQuery) Point(org.springframework.data.geo.Point) Test(org.junit.Test)

Example 2 with Point

use of org.springframework.data.geo.Point in project spring-data-mongodb by spring-projects.

the class MongoOperationsUnitTests method geoNearRejectsNullEntityClass.

// DATAMONGO-341
@Test
public void geoNearRejectsNullEntityClass() {
    final NearQuery query = NearQuery.near(new Point(10, 20));
    new Execution() {

        @Override
        public void doWith(MongoOperations operations) {
            operations.geoNear(query, null);
        }
    }.assertDataAccessException();
}
Also used : NearQuery(org.springframework.data.mongodb.core.query.NearQuery) Point(org.springframework.data.geo.Point) Test(org.junit.Test)

Example 3 with Point

use of org.springframework.data.geo.Point in project spring-data-mongodb by spring-projects.

the class AbstractPersonRepositoryIntegrationTests method executesGeoPageQueryForWithPageRequestForPageInBetween.

// DATAMONGO-445
@Test
public void executesGeoPageQueryForWithPageRequestForPageInBetween() {
    Point farAway = new Point(-73.9, 40.7);
    Point here = new Point(-73.99, 40.73);
    dave.setLocation(farAway);
    oliver.setLocation(here);
    carter.setLocation(here);
    boyd.setLocation(here);
    leroi.setLocation(here);
    repository.saveAll(Arrays.asList(dave, oliver, carter, boyd, leroi));
    GeoPage<Person> results = repository.findByLocationNear(new Point(-73.99, 40.73), new Distance(2000, Metrics.KILOMETERS), PageRequest.of(1, 2));
    assertThat(results.getContent().isEmpty(), is(false));
    assertThat(results.getNumberOfElements(), is(2));
    assertThat(results.isFirst(), is(false));
    assertThat(results.isLast(), is(false));
    assertThat(results.getAverageDistance().getMetric(), is((Metric) Metrics.KILOMETERS));
    assertThat(results.getAverageDistance().getNormalizedValue(), is(0.0));
}
Also used : Metric(org.springframework.data.geo.Metric) Point(org.springframework.data.geo.Point) GeoJsonPoint(org.springframework.data.mongodb.core.geo.GeoJsonPoint) Distance(org.springframework.data.geo.Distance) Test(org.junit.Test)

Example 4 with Point

use of org.springframework.data.geo.Point in project spring-data-mongodb by spring-projects.

the class AbstractPersonRepositoryIntegrationTests method executesGeoNearQueryForResultsCorrectlyWhenGivenMinAndMaxDistance.

// DATAMONGO-1110
@Test
public void executesGeoNearQueryForResultsCorrectlyWhenGivenMinAndMaxDistance() {
    Point point = new Point(-73.99171, 40.738868);
    dave.setLocation(point);
    repository.save(dave);
    Range<Distance> range = Distance.between(new Distance(0.01, KILOMETERS), new Distance(2000, KILOMETERS));
    GeoResults<Person> results = repository.findPersonByLocationNear(new Point(-73.99, 40.73), range);
    assertThat(results.getContent().isEmpty(), is(false));
}
Also used : Point(org.springframework.data.geo.Point) GeoJsonPoint(org.springframework.data.mongodb.core.geo.GeoJsonPoint) Distance(org.springframework.data.geo.Distance) Test(org.junit.Test)

Example 5 with Point

use of org.springframework.data.geo.Point in project spring-data-mongodb by spring-projects.

the class AbstractPersonRepositoryIntegrationTests method findsPeopleByLocationWithinCircle.

@Test
public void findsPeopleByLocationWithinCircle() {
    Point point = new Point(-73.99171, 40.738868);
    dave.setLocation(point);
    repository.save(dave);
    List<Person> result = repository.findByLocationWithin(new Circle(-78.99171, 45.738868, 170));
    assertThat(result.size(), is(1));
    assertThat(result, hasItem(dave));
}
Also used : Circle(org.springframework.data.geo.Circle) Point(org.springframework.data.geo.Point) GeoJsonPoint(org.springframework.data.mongodb.core.geo.GeoJsonPoint) Test(org.junit.Test)

Aggregations

Point (org.springframework.data.geo.Point)90 Test (org.junit.Test)86 Distance (org.springframework.data.geo.Distance)26 GeoJsonPoint (org.springframework.data.mongodb.core.geo.GeoJsonPoint)26 Document (org.bson.Document)21 Query (org.springframework.data.mongodb.core.query.Query)14 Document (org.springframework.data.mongodb.core.mapping.Document)13 Circle (org.springframework.data.geo.Circle)11 Sphere (org.springframework.data.mongodb.core.geo.Sphere)9 Polygon (org.springframework.data.geo.Polygon)7 NearQuery (org.springframework.data.mongodb.core.query.NearQuery)7 PartTree (org.springframework.data.repository.query.parser.PartTree)7 Method (java.lang.reflect.Method)6 Box (org.springframework.data.geo.Box)6 Shape (org.springframework.data.geo.Shape)6 Metric (org.springframework.data.geo.Metric)5 Venue (org.springframework.data.mongodb.core.Venue)5 Pageable (org.springframework.data.domain.Pageable)4 GeospatialIndex (org.springframework.data.mongodb.core.index.GeospatialIndex)4 Arrays (java.util.Arrays)3