Search in sources :

Example 31 with Distance

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

the class AbstractPersonRepositoryIntegrationTests method executesGeoPageQueryForWithPageRequestForJustOneElement.

// DATAMONGO-445
@Test
void executesGeoPageQueryForWithPageRequestForJustOneElement() {
    Point point = new Point(-73.99171, 40.738868);
    dave.setLocation(point);
    repository.save(dave);
    GeoPage<Person> results = repository.findByLocationNear(new Point(-73.99, 40.73), new Distance(2000, Metrics.KILOMETERS), PageRequest.of(0, 2));
    assertThat(results.getContent()).isNotEmpty();
    assertThat(results.getNumberOfElements()).isEqualTo(1);
    assertThat(results.isFirst()).isTrue();
    assertThat(results.isLast()).isTrue();
    assertThat(results.getAverageDistance().getMetric()).isEqualTo((Metric) Metrics.KILOMETERS);
}
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.jupiter.api.Test)

Example 32 with Distance

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

the class AbstractPersonRepositoryIntegrationTests method executesGeoNearQueryForResultsCorrectly.

@Test
void executesGeoNearQueryForResultsCorrectly() {
    Point point = new Point(-73.99171, 40.738868);
    dave.setLocation(point);
    repository.save(dave);
    GeoResults<Person> results = repository.findByLocationNear(new Point(-73.99, 40.73), new Distance(2000, Metrics.KILOMETERS));
    assertThat(results.getContent()).isNotEmpty();
}
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.jupiter.api.Test)

Example 33 with Distance

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

the class AbstractPersonRepositoryIntegrationTests method executesGeoPageQueryForWithPageRequestForJustOneElementEmptyPage.

// DATAMONGO-445
@Test
void executesGeoPageQueryForWithPageRequestForJustOneElementEmptyPage() {
    dave.setLocation(new Point(-73.99171, 40.738868));
    repository.save(dave);
    GeoPage<Person> results = repository.findByLocationNear(new Point(-73.99, 40.73), new Distance(2000, Metrics.KILOMETERS), PageRequest.of(1, 2));
    assertThat(results.getContent()).isEmpty();
    assertThat(results.getNumberOfElements()).isEqualTo(0);
    assertThat(results.isFirst()).isFalse();
    assertThat(results.isLast()).isTrue();
    assertThat(results.getAverageDistance().getMetric()).isEqualTo((Metric) Metrics.KILOMETERS);
}
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.jupiter.api.Test)

Example 34 with Distance

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

the class MetricConversionUnitTests method shouldConvertMilesToMeters.

// DATAMONGO-1348
@Test
public void shouldConvertMilesToMeters() {
    Distance distance = new Distance(1, Metrics.MILES);
    double distanceInMeters = MetricConversion.getDistanceInMeters(distance);
    assertThat(distanceInMeters).isCloseTo(1609.3438343d, offset(0.000000001));
}
Also used : Distance(org.springframework.data.geo.Distance) Test(org.junit.jupiter.api.Test)

Example 35 with Distance

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

the class NearQueryUnitTests method shouldUseMetersForGeoJsonDataWhenDistanceInMiles.

// DATAMONGO-1348
@Test
public void shouldUseMetersForGeoJsonDataWhenDistanceInMiles() {
    NearQuery query = NearQuery.near(new GeoJsonPoint(27.987901, 86.9165379));
    query.maxDistance(new Distance(1, Metrics.MILES));
    assertThat(query.toDocument()).containsEntry("maxDistance", 1609.3438343D).containsEntry("distanceMultiplier", 0.00062137D);
}
Also used : GeoJsonPoint(org.springframework.data.mongodb.core.geo.GeoJsonPoint) Distance(org.springframework.data.geo.Distance) Test(org.junit.jupiter.api.Test)

Aggregations

Distance (org.springframework.data.geo.Distance)44 Test (org.junit.jupiter.api.Test)34 Point (org.springframework.data.geo.Point)32 GeoJsonPoint (org.springframework.data.mongodb.core.geo.GeoJsonPoint)17 Query (org.springframework.data.mongodb.core.query.Query)9 Test (org.junit.Test)6 Product (com.nixmash.blog.solr.model.Product)5 Document (org.bson.Document)5 Circle (org.springframework.data.geo.Circle)5 Document (org.springframework.data.mongodb.core.mapping.Document)5 PartTree (org.springframework.data.repository.query.parser.PartTree)5 Sphere (org.springframework.data.mongodb.core.geo.Sphere)4 Arrays (java.util.Arrays)3 Sort (org.springframework.data.domain.Sort)3 Metrics (org.springframework.data.geo.Metrics)3 MongoClient (com.mongodb.reactivestreams.client.MongoClient)2 Method (java.lang.reflect.Method)2 Map (java.util.Map)2 BlockingQueue (java.util.concurrent.BlockingQueue)2 LinkedBlockingDeque (java.util.concurrent.LinkedBlockingDeque)2