Java Code Examples for com.spatial4j.core.distance.DistanceUtils#degrees2Dist()

The following examples show how to use com.spatial4j.core.distance.DistanceUtils#degrees2Dist() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NavUtils.java    From Real-Time-Taxi-Dispatch-Simulator with MIT License 5 votes vote down vote up
/**
 * Returns distance (in meters) between 2 points.
 *
 * @param point1 Must not be null
 * @param point2 Must not be null
 * @return distance in meters
 */
public static double getDistance(Point point1, Point point2) {
    Assert.notNull(point1, "point1 must not be null");
    Assert.notNull(point2, "point2 must not be null");

    final SpatialContext ctx = SpatialContext.GEO;
    com.spatial4j.core.shape.Point p1 = ctx.makePoint(point1.getLongitude(), point1.getLatitude());
    com.spatial4j.core.shape.Point p2 = ctx.makePoint(point2.getLongitude(), point2.getLatitude());

    return DistanceUtils.degrees2Dist(ctx.getDistCalc().distance(p1, p2), DistanceUtils.EARTH_MEAN_RADIUS_KM) * 1000;
}
 
Example 2
Source File: OLuceneSpatialIndexManager.java    From orientdb-lucene with Apache License 2.0 5 votes vote down vote up
@Override
public void onRecordAddedToResultSet(QueryContext queryContext, OContextualRecordId recordId, Document doc, ScoreDoc score) {

  SpatialQueryContext spatialContext = (SpatialQueryContext) queryContext;
  if (spatialContext.spatialArgs != null) {
    Point docPoint = (Point) ctx.readShape(doc.get(strategy.getFieldName()));
    double docDistDEG = ctx.getDistCalc().distance(spatialContext.spatialArgs.getShape().getCenter(), docPoint);
    final double docDistInKM = DistanceUtils.degrees2Dist(docDistDEG, DistanceUtils.EARTH_EQUATORIAL_RADIUS_KM);
    recordId.setContext(new HashMap<String, Object>() {
      {
        put("distance", docDistInKM);
      }
    });
  }
}
 
Example 3
Source File: OLuceneNearOperator.java    From orientdb-lucene with Apache License 2.0 5 votes vote down vote up
@Override
public Object evaluateRecord(OIdentifiable iRecord, ODocument iCurrentResult, OSQLFilterCondition iCondition, Object iLeft,
    Object iRight, OCommandContext iContext) {

  List<Number> left = (List<Number>) iLeft;

  double lat = left.get(0).doubleValue();
  double lon = left.get(1).doubleValue();

  Shape shape = SpatialContext.GEO.makePoint(lon, lat);
  List<Number> right = (List<Number>) iRight;

  double lat1 =  right.get(0).doubleValue();
  double lon1 =  right.get(1).doubleValue();
  Shape shape1 = SpatialContext.GEO.makePoint(lon1, lat1);

  Map map = (Map) right.get(2);
  double distance = 0;

  Number n = (Number) map.get("maxDistance");
  if (n != null) {
    distance = n.doubleValue();
  }
  Point p = (Point) shape1;
  Circle circle = SpatialContext.GEO.makeCircle(p.getX(), p.getY(),
      DistanceUtils.dist2Degrees(distance, DistanceUtils.EARTH_MEAN_RADIUS_KM));
  double docDistDEG = SpatialContext.GEO.getDistCalc().distance((Point) shape, p);
  final double docDistInKM = DistanceUtils.degrees2Dist(docDistDEG, DistanceUtils.EARTH_EQUATORIAL_RADIUS_KM);
  iContext.setVariable("distance", docDistInKM);
  return shape.relate(circle) == SpatialRelation.WITHIN;
}
 
Example 4
Source File: Geoshape.java    From titan1withtp3.1 with Apache License 2.0 2 votes vote down vote up
/**
 * Returns the distance to another point in kilometers
 *
 * @param other Point
 * @return
 */
public double distance(Point other) {
    return DistanceUtils.degrees2Dist(CTX.getDistCalc().distance(getSpatial4jPoint(),other.getSpatial4jPoint()),DistanceUtils.EARTH_MEAN_RADIUS_KM);
}