Package org.springframework.data.geo

Examples of org.springframework.data.geo.Distance


    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));
View Full Code Here


    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));
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, 2));

    assertThat(results.getContent().isEmpty(), is(false));
    assertThat(results.getNumberOfElements(), is(1));
    assertThat(results.isFirst(), is(true));
View Full Code Here

  public 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), new PageRequest(1, 2));

    assertThat(results.getContent().isEmpty(), is(true));
    assertThat(results.getNumberOfElements(), is(0));
    assertThat(results.isFirst(), is(false));
View Full Code Here

  @Test
  public void bindsMetricDistanceParameterToNearSphereCorrectly() throws Exception {

    Point point = new Point(10, 20);
    Distance distance = new Distance(2.5, Metrics.KILOMETERS);

    Query query = query(where("location").nearSphere(point).maxDistance(distance.getNormalizedValue()).and("firstname")
        .is("Dave"));
    assertBindsDistanceToQuery(point, distance, query);
  }
View Full Code Here

  @Test
  public void bindsDistanceParameterToNearCorrectly() throws Exception {

    Point point = new Point(10, 20);
    Distance distance = new Distance(2.5);

    Query query = query(where("location").near(point).maxDistance(distance.getNormalizedValue()).and("firstname")
        .is("Dave"));
    assertBindsDistanceToQuery(point, distance, query);
  }
View Full Code Here

        return criteria.is(true);
      case FALSE:
        return criteria.is(false);
      case NEAR:

        Distance distance = accessor.getMaxDistance();
        Point point = accessor.getGeoNearLocation();
        point = point == null ? nextAs(parameters, Point.class) : point;

        if (distance == null) {
          return criteria.near(point);
        } else {
          if (distance.getMetric() != null) {
            criteria.nearSphere(point);
          } else {
            criteria.near(point);
          }
          criteria.maxDistance(distance.getNormalizedValue());
        }
        return criteria;
      case WITHIN:

        Object parameter = parameters.next();
View Full Code Here

      if (query != null) {
        nearQuery.query(query);
      }

      Distance maxDistance = accessor.getMaxDistance();
      if (maxDistance != null) {
        nearQuery.maxDistance(maxDistance).in(maxDistance.getMetric());
      }

      Pageable pageable = accessor.getPageable();
      if (pageable != null) {
        nearQuery.with(pageable);
View Full Code Here

    query = query.in(Metrics.MILES);
    assertThat(query.getMetric(), is((Metric) Metrics.MILES));
    assertThat(query.getMaxDistance(), is(ONE_FIFTY_KILOMETERS));
    assertThat(query.isSpherical(), is(true));

    query = query.maxDistance(new Distance(200, Metrics.KILOMETERS));
    assertThat(query.getMetric(), is((Metric) Metrics.MILES));
  }
View Full Code Here

  @Test
  public void testCreateQueryWithNear() throws NoSuchMethodException, SecurityException {
    Method method = SampleRepository.class.getMethod("findByLocationNear", Point.class, Distance.class);

    Query query = createQueryForMethodWithArgs(method,
        new Object[] { new Point(48.303056, 14.290556), new Distance(5) });
    Assert.assertEquals("{!bbox pt=48.303056,14.290556 sfield=store d=5.0}", queryParser.getQueryString(query));
  }
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.