Java Code Examples for org.locationtech.spatial4j.shape.Shape#relate()

The following examples show how to use org.locationtech.spatial4j.shape.Shape#relate() . 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: PackedQuadPrefixTree.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
protected void checkBattenbergNotRobustly(byte quad, double cx, double cy, int level, List<Cell> matches,
                               long term, Shape shape, int maxLevel) {
  // short-circuit if we find a match for the point (no need to continue recursion)
  if (shape instanceof Point && !matches.isEmpty())
    return;
  double w = levelW[level] / 2;
  double h = levelH[level] / 2;

  SpatialRelation v = shape.relate(ctx.getShapeFactory().rect(cx - w, cx + w, cy - h, cy + h));

  if (SpatialRelation.DISJOINT == v) {
    return;
  }

  // set bits for next level
  term |= (((long)(quad))<<(64-(++level<<1)));
  // increment level
  term = ((term>>>1)+1)<<1;

  if (SpatialRelation.CONTAINS == v || (level >= maxLevel)) {
    matches.add(new PackedQuadCell(term, v.transpose()));
  } else {// SpatialRelation.WITHIN, SpatialRelation.INTERSECTS
    buildNotRobustly(cx, cy, level, matches, term, shape, maxLevel);
  }
}
 
Example 2
Source File: GeoShapeType.java    From crate with Apache License 2.0 5 votes vote down vote up
@Override
public int compare(Map<String, Object> val1, Map<String, Object> val2) {
    // TODO: compare without converting to shape
    Shape shape1 = GeoJSONUtils.map2Shape(val1);
    Shape shape2 = GeoJSONUtils.map2Shape(val2);
    switch (shape1.relate(shape2)) {
        case WITHIN:
            return -1;
        case CONTAINS:
            return 1;
        default:
            return Double.compare(shape1.getArea(JtsSpatialContext.GEO), shape2.getArea(JtsSpatialContext.GEO));
    }
}
 
Example 3
Source File: DefaultSpatialAlgebra.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public boolean sfDisjoint(Shape s1, Shape s2) {
	return SpatialRelation.DISJOINT == s1.relate(s2);
}
 
Example 4
Source File: DefaultSpatialAlgebra.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public boolean sfIntersects(Shape s1, Shape s2) {
	return SpatialRelation.INTERSECTS == s1.relate(s2);
}
 
Example 5
Source File: DefaultSpatialAlgebra.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public boolean ehDisjoint(Shape s1, Shape s2) {
	return SpatialRelation.DISJOINT == s1.relate(s2);
}
 
Example 6
Source File: DefaultSpatialAlgebra.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public boolean ehCovers(Shape s1, Shape s2) {
	return SpatialRelation.CONTAINS == s1.relate(s2);
}
 
Example 7
Source File: DefaultSpatialAlgebra.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public boolean ehCoveredBy(Shape s1, Shape s2) {
	return SpatialRelation.WITHIN == s1.relate(s2);
}
 
Example 8
Source File: SpatialOperation.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
@Override
public boolean evaluate(Shape indexedShape, Shape queryShape) {
  return indexedShape.relate(queryShape) == SpatialRelation.CONTAINS || indexedShape.equals(queryShape);
}
 
Example 9
Source File: SpatialOperation.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
@Override
public boolean evaluate(Shape indexedShape, Shape queryShape) {
  return indexedShape.relate(queryShape) == SpatialRelation.WITHIN || indexedShape.equals(queryShape);
}
 
Example 10
Source File: SpatialOperation.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
@Override
public boolean evaluate(Shape indexedShape, Shape queryShape) {
  return indexedShape.relate(queryShape) == SpatialRelation.INTERSECTS;//not Contains or Within or Disjoint
}