Example usage for org.springframework.data.geo Metrics KILOMETERS

List of usage examples for org.springframework.data.geo Metrics KILOMETERS

Introduction

In this page you can find the example usage for org.springframework.data.geo Metrics KILOMETERS.

Prototype

Metrics KILOMETERS

To view the source code for org.springframework.data.geo Metrics KILOMETERS.

Click Source Link

Usage

From source file:org.springframework.data.geo.GeoModuleIntegrationTests.java

@Test // DATACMNS-475
public void deserializesDistance() throws Exception {

    String json = "{\"value\":10.0,\"metric\":\"KILOMETERS\"}";
    Distance reference = new Distance(10.0, Metrics.KILOMETERS);

    assertThat(mapper.readValue(json, Distance.class)).isEqualTo(reference);
    assertThat(mapper.writeValueAsString(reference)).isEqualTo(json);
}

From source file:com.couchbase.trombi.services.SearchService.java

public List<Coworker> findCoworkersNear(String imHandle) {
    List<Coworker> lc = coworkerRepository.findAllByIm(imHandle);
    if (lc == null || lc.isEmpty()) {
        return Collections.emptyList();
    }/* w ww.jav  a2  s .  c  om*/
    Coworker c = lc.get(0);

    Location latest = c.getLastCheckin();
    if (latest == null) {
        latest = c.getMainLocation();
    }

    return coworkerRepository.findAllByMainLocationCoordinatesNear(latest.getCoordinates(),
            new Distance(10, Metrics.KILOMETERS));
}

From source file:example.springdata.rest.stores.StoreRepositoryIntegrationTests.java

@Test
public void findsStoresByLocation() {

    Point location = new Point(-73.995146, 40.740337);
    Store store = new Store("Foo", new Address("street", "city", "zip", location));

    store = repository.save(store);//  w  w w  .j a v  a 2 s.c  o m

    Page<Store> stores = repository.findByAddressLocationNear(location, new Distance(1.0, Metrics.KILOMETERS),
            new PageRequest(0, 10));

    assertThat(stores.getContent(), hasSize(1));
    assertThat(stores.getContent(), hasItem(store));
}

From source file:org.springframework.data.geo.GeoModuleIntegrationTests.java

@Test // DATACMNS-475
public void deserializesCircle() throws Exception {

    String json = "{\"center\":{\"x\":10.0,\"y\":20.0},\"radius\":{\"value\":10.0,\"metric\":\"KILOMETERS\"}}";
    Circle reference = new Circle(new Point(10.0, 20.0), new Distance(10, Metrics.KILOMETERS));

    assertThat(mapper.readValue(json, Circle.class)).isEqualTo(reference);
    assertThat(mapper.writeValueAsString(reference)).isEqualTo(json);
}

From source file:com.ninjas.movietime.repository.TheaterRepository.java

public GeoPage<Theater> listByGeoLocation(Point point, PageRequest pageRequest) {
    Preconditions.checkNotNull(point);/* w ww .j  a v a 2s.c  o  m*/
    Preconditions.checkNotNull(pageRequest);

    final NearQuery nearQuery = NearQuery.near(point).spherical(true).maxDistance(1, Metrics.KILOMETERS)
            .with(pageRequest);

    //final int size = getMongoTemplate().geoNear(nearQuery, Theater.class).getContent().size();

    final GeoResults<Theater> geoResults = getMongoTemplate().geoNear(nearQuery, Theater.class);

    final GeoPage<Theater> geoPage = new GeoPage<>(geoResults, pageRequest, 0);

    return geoPage;
}

From source file:example.springdata.mongodb.customer.CustomerRepositoryIntegrationTest.java

/**
 * Test case to show the usage of the geo-spatial APIs to lookup people within a given distance of a reference point.
 *///  w  w w  .  j  av  a  2  s.  c o  m
@Test
public void exposesGeoSpatialFunctionality() {

    GeospatialIndex indexDefinition = new GeospatialIndex("address.location");
    indexDefinition.getIndexOptions().put("min", -180);
    indexDefinition.getIndexOptions().put("max", 180);

    operations.indexOps(Customer.class).ensureIndex(indexDefinition);

    Customer ollie = new Customer("Oliver", "Gierke");
    ollie.setAddress(new Address(new Point(52.52548, 13.41477)));
    ollie = repository.save(ollie);

    Point referenceLocation = new Point(52.51790, 13.41239);
    Distance oneKilometer = new Distance(1, Metrics.KILOMETERS);

    GeoResults<Customer> result = repository.findByAddressLocationNear(referenceLocation, oneKilometer);

    assertThat(result.getContent(), hasSize(1));

    Distance distanceToFirstStore = result.getContent().get(0).getDistance();
    assertThat(distanceToFirstStore.getMetric(), is(Metrics.KILOMETERS));
    assertThat(distanceToFirstStore.getValue(), closeTo(0.862, 0.001));
}

From source file:com.afmobi.mongodb.repository.PersonRepositoryIntegrationTests.java

@Test
public void executesGeoNearQueryForResultsCorrectly() {
    Point point = new Point(-73.99171, 40.738868);
    dave.setLocation(point);/*  w  w  w  .j  a va 2  s .c o m*/
    repository.save(dave);

    GeoResults<Person> results = repository.findByLocationNear(new Point(-73.99, 40.73),
            new Distance(2000, Metrics.KILOMETERS));
    assertThat(results.getContent().isEmpty(), is(false));
}

From source file:com.afmobi.mongodb.repository.PersonRepositoryIntegrationTests.java

@Test
public void executesGeoPageQueryForResultsCorrectly() {
    Point point = new Point(-73.99171, 40.738868);
    dave.setLocation(point);/*  ww w .  j av  a  2s .  c  om*/
    repository.save(dave);

    GeoPage<Person> results = repository.findByLocationNear(new Point(-73.99, 40.73),
            new Distance(2000, Metrics.KILOMETERS), new PageRequest(0, 20));
    assertThat(results.getContent().isEmpty(), is(false));

    // DATAMONGO-607
    assertThat(results.getAverageDistance().getMetric(), is((Metric) Metrics.KILOMETERS));
}

From source file:com.afmobi.mongodb.repository.PersonRepositoryIntegrationTests.java

@Test
public void executesGeoPageQueryForWithPageRequestForPageInBetween() {
    Point farAway = new Point(-73.9, 40.7);
    Point here = new Point(-73.99, 40.73);

    dave.setLocation(farAway);//from w  w w  .  j  a  v  a2 s  . c om
    oliver.setLocation(here);
    carter.setLocation(here);
    boyd.setLocation(here);
    leroi.setLocation(here);

    repository.save(Arrays.asList(dave, oliver, carter, boyd, leroi));

    GeoPage<Person> results = repository.findByLocationNear(new Point(-73.99, 40.73),
            new Distance(2000, Metrics.KILOMETERS), new PageRequest(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));
}

From source file:com.afmobi.mongodb.repository.PersonRepositoryIntegrationTests.java

@Test
public void executesGeoPageQueryForWithPageRequestForPageAtTheEnd() {
    Point point = new Point(-73.99171, 40.738868);

    dave.setLocation(point);//w w  w.  j  a  v a 2  s  .  com
    oliver.setLocation(point);
    carter.setLocation(point);

    repository.save(Arrays.asList(dave, oliver, carter));

    GeoPage<Person> results = repository.findByLocationNear(new Point(-73.99, 40.73),
            new Distance(2000, Metrics.KILOMETERS), new PageRequest(1, 2));
    assertThat(results.getContent().isEmpty(), is(false));
    assertThat(results.getNumberOfElements(), is(1));
    assertThat(results.isFirst(), is(false));
    assertThat(results.isLast(), is(true));
    assertThat(results.getAverageDistance().getMetric(), is((Metric) Metrics.KILOMETERS));
}