Package org.springframework.data.geo

Examples of org.springframework.data.geo.Distance


   * @see DATAREST-279
   */
  @Test
  public void parsesDistanceFromString() {

    Distance reference = new Distance(10.8, Metrics.KILOMETERS);

    assertThat(INSTANCE.convert("10.8km"), is(reference));
    assertThat(INSTANCE.convert(" 10.8km"), is(reference));
    assertThat(INSTANCE.convert(" 10.8 km"), is(reference));
    assertThat(INSTANCE.convert(" 10.8 km "), is(reference));
View Full Code Here


   */
  public Criteria within(Point location, Distance distance) {
    Assert.notNull(location);
    assertPositiveDistanceValue(distance);
    predicates.add(new Predicate(OperationKey.WITHIN, new Object[] { location,
        distance != null ? distance : new Distance(0) }));
    return this;
  }
View Full Code Here

  public Criteria near(Point location, Distance distance) {
    Assert.notNull(location, "Location must not be 'null' for near criteria.");
    assertPositiveDistanceValue(distance);

    predicates.add(new Predicate(OperationKey.NEAR, new Object[] { location,
        distance != null ? distance : new Distance(0) }));
    return this;
  }
View Full Code Here

    sampleEntity.setLocation(new GeoPoint(45.7806d, 3.0875d));

    repository.save(sampleEntity);

    // when
    Page<SampleEntity> page = repository.findByLocationWithin(new Point(3.0875d, 45.7806d), new Distance(2, Metrics.KILOMETERS), new PageRequest(0, 10));
    // then
    assertThat(page, is(notNullValue()));
    assertThat(page.getTotalElements(), is(equalTo(1L)));
  }
View Full Code Here

    sampleEntity.setLocation(new GeoPoint(45.7806d, 3.0875d));

    repository.save(sampleEntity);

    // when
    Page<SampleEntity> page = repository.findByLocationNear(new Point(3.0875d, 45.7806d), new Distance(2, Metrics.KILOMETERS), new PageRequest(0, 10));
    // then
    assertThat(page, is(notNullValue()));
    assertThat(page.getTotalElements(), is(equalTo(1L)));
  }
View Full Code Here

    sampleEntity2.setLocation(new GeoPoint(30.7806d, 0.0875d));

    repository.save(sampleEntity2);

    // when
    long count = repository.countByLocationWithin(new Point(3.0875d, 45.7806d), new Distance(2, Metrics.KILOMETERS));
    // then
    assertThat(count, is(equalTo(1L)));
  }
View Full Code Here

    sampleEntity2.setLocation(new GeoPoint(30.7806d, 0.0875d));

    repository.save(sampleEntity2);

    // when
    long count = repository.countByLocationNear(new Point(3.0875d, 45.7806d), new Distance(2, Metrics.KILOMETERS));
    // then
    assertThat(count, is(equalTo(1L)));
  }
View Full Code Here

   *
   * @param maxDistance
   * @return
   */
  public NearQuery maxDistance(double maxDistance) {
    return maxDistance(new Distance(maxDistance, getMetric()));
  }
View Full Code Here

   * @return
   */
  public NearQuery maxDistance(double maxDistance, Metric metric) {

    Assert.notNull(metric);
    return maxDistance(new Distance(maxDistance, metric));
  }
View Full Code Here

  @Test
  public void shouldWriteEntityWithGeoCircleCorrectly() {

    ClassWithGeoCircle object = new ClassWithGeoCircle();
    Circle circle = new Circle(new Point(1, 2), 3);
    Distance radius = circle.getRadius();
    object.circle = circle;

    DBObject dbo = new BasicDBObject();
    converter.write(object, dbo);

    assertThat(dbo, is(notNullValue()));
    assertThat(dbo.get("circle"), is(instanceOf(DBObject.class)));
    assertThat(
        dbo.get("circle"),
        is((Object) new BasicDBObject("center", new BasicDBObject("x", circle.getCenter().getX()).append("y", circle
            .getCenter().getY())).append("radius", radius.getNormalizedValue()).append("metric",
            radius.getMetric().toString())));
  }
View Full Code Here

TOP

Related Classes of org.springframework.data.geo.Distance

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.