Package org.springframework.data.geo

Examples of org.springframework.data.geo.Distance


  @Test
  public void shouldWriteEntityWithGeoSphereCorrectly() {

    ClassWithGeoSphere object = new ClassWithGeoSphere();
    Sphere sphere = new Sphere(new Point(1, 2), 3);
    Distance radius = sphere.getRadius();
    object.sphere = sphere;

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

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


   */
  @Test
  public void shouldWriteEntityWithGeoSphereWithMetricDistanceCorrectly() {

    ClassWithGeoSphere object = new ClassWithGeoSphere();
    Sphere sphere = new Sphere(new Point(1, 2), new Distance(3, Metrics.KILOMETERS));
    Distance radius = sphere.getRadius();
    object.sphere = sphere;

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

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

  @Test
  public void shouldWriteEntityWithGeoShapeCorrectly() {

    ClassWithGeoShape object = new ClassWithGeoShape();
    Sphere sphere = new Sphere(new Point(1, 2), 3);
    Distance radius = sphere.getRadius();
    object.shape = sphere;

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

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

   *
   * @param center
   * @param radius
   */
  public Sphere(Point center, double radius) {
    this(center, new Distance(radius));
  }
View Full Code Here

      double distance = ((Double) object.get("dis")).doubleValue();
      DBObject content = (DBObject) object.get("obj");

      T doWith = delegate.doWith(content);

      return new GeoResult<T>(doWith, new Distance(distance, metric));
    }
View Full Code Here

      return new GeoResults<T>(result, near.getMetric());
    }

    DBObject stats = (DBObject) commandResult.get("stats");
    double averageDistance = stats == null ? 0 : (Double) stats.get("avgDistance");
    return new GeoResults<T>(result, new Distance(averageDistance, near.getMetric()));
  }
View Full Code Here

   * @see DATAMONGO-858
   */
  @Test
  public void convertsCircleToDbObjectAndBackCorrectlyMilesDistance() {

    Distance radius = new Distance(3, Metrics.MILES);
    Circle circle = new Circle(new Point(1, 2), radius);

    DBObject dbo = CircleToDbObjectConverter.INSTANCE.convert(circle);
    Circle result = DbObjectToCircleConverter.INSTANCE.convert(dbo);

View Full Code Here

   * @see DATAMONGO-858
   */
  @Test
  public void convertsSphereToDbObjectAndBackCorrectlyWithKilometerDistance() {

    Distance radius = new Distance(3, Metrics.KILOMETERS);
    Sphere sphere = new Sphere(new Point(1, 2), radius);

    DBObject dbo = SphereToDbObjectConverter.INSTANCE.convert(sphere);
    Sphere result = DbObjectToSphereConverter.INSTANCE.convert(dbo);

View Full Code Here

    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().isEmpty(), is(false));
  }
View Full Code Here

    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), new PageRequest(0, 20));
    assertThat(results.getContent().isEmpty(), is(false));

    // DATAMONGO-607
    assertThat(results.getAverageDistance().getMetric(), is((Metric) Metrics.KILOMETERS));
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.