com.spatial4j.core.shape.SpatialRelation Java Examples

The following examples show how to use com.spatial4j.core.shape.SpatialRelation. 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: 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 #2
Source File: OLuceneWithinOperator.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);

  Shape shape1 = shapeFactory.makeShape(new OSpatialCompositeKey((List<?>) iRight), SpatialContext.GEO);

  return shape.relate(shape1) == SpatialRelation.WITHIN;
}
 
Example #3
Source File: Geoshape.java    From titan1withtp3.1 with Apache License 2.0 4 votes vote down vote up
private SpatialRelation getSpatialRelation(Geoshape other) {
    Preconditions.checkNotNull(other);
    return convert2Spatial4j().relate(other.convert2Spatial4j());
}
 
Example #4
Source File: Geoshape.java    From titan1withtp3.1 with Apache License 2.0 4 votes vote down vote up
public boolean intersect(Geoshape other) {
    SpatialRelation r = getSpatialRelation(other);
    return r==SpatialRelation.INTERSECTS || r==SpatialRelation.CONTAINS || r==SpatialRelation.WITHIN;
}
 
Example #5
Source File: Geoshape.java    From titan1withtp3.1 with Apache License 2.0 4 votes vote down vote up
public boolean within(Geoshape outer) {
    return getSpatialRelation(outer)==SpatialRelation.WITHIN;
}
 
Example #6
Source File: Geoshape.java    From titan1withtp3.1 with Apache License 2.0 4 votes vote down vote up
public boolean disjoint(Geoshape other) {
    return getSpatialRelation(other)==SpatialRelation.DISJOINT;
}