List of usage examples for org.springframework.data.geo Distance Distance
public Distance(double value, Metric metric)
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(); }//from www . ja v a 2 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 ww . j a va 2 s . c om*/ 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:example.springdata.redis.commands.GeoOperationsTests.java
/** * Look up points using a geo-index member as reference. *///w w w.ja va 2 s. com @Test public void geoRadiusByMember() { GeoResults<GeoLocation<String>> byDistance = geoOperations.geoRadiusByMember("Sicily", "Palermo", new Distance(100, DistanceUnit.KILOMETERS)); assertThat(byDistance).hasSize(2).extracting("content.name").contains("Arigento", "Palermo"); GeoResults<GeoLocation<String>> greaterDistance = geoOperations.geoRadiusByMember("Sicily", "Palermo", new Distance(200, DistanceUnit.KILOMETERS)); assertThat(greaterDistance).hasSize(3).extracting("content.name").contains("Arigento", "Catania", "Palermo"); }
From source file:example.springdata.redis.commands.GeoOperationsTests.java
/** * Lookup points within a circle around coordinates. *///from ww w. j a v a2 s . c o m @Test public void geoRadius() { Circle circle = new Circle(new Point(13.583333, 37.316667), // new Distance(100, DistanceUnit.KILOMETERS)); GeoResults<GeoLocation<String>> result = geoOperations.geoRadius("Sicily", circle); assertThat(result).hasSize(2).extracting("content.name").contains("Arigento", "Palermo"); }
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. *//*from ww w.ja va 2 s .c om*/ @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);// ww w .ja va 2 s . co 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);/*from w ww . j a v a 2 s. 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 ww w. ja 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)); }