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