Java Code Examples for org.locationtech.spatial4j.shape.SpatialRelation#DISJOINT

The following examples show how to use org.locationtech.spatial4j.shape.SpatialRelation#DISJOINT . 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: NumberRangePrefixTree.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
public SpatialRelation relate(SpanUnitsNRShape ext) {
  //This logic somewhat mirrors RectangleImpl.relate_range()
  int extMin_intMax = comparePrefix(ext.getMinUnit(), getMaxUnit());
  if (extMin_intMax > 0)
    return SpatialRelation.DISJOINT;
  int extMax_intMin = comparePrefix(ext.getMaxUnit(), getMinUnit());
  if (extMax_intMin < 0)
    return SpatialRelation.DISJOINT;
  int extMin_intMin = comparePrefix(ext.getMinUnit(), getMinUnit());
  int extMax_intMax = comparePrefix(ext.getMaxUnit(), getMaxUnit());
  if ((extMin_intMin > 0 || extMin_intMin == 0 && ext.getMinUnit().getLevel() >= getMinUnit().getLevel())
      && (extMax_intMax < 0 || extMax_intMax == 0 && ext.getMaxUnit().getLevel() >= getMaxUnit().getLevel()))
    return SpatialRelation.CONTAINS;
  if ((extMin_intMin < 0 || extMin_intMin == 0 && ext.getMinUnit().getLevel() <= getMinUnit().getLevel())
      && (extMax_intMax > 0 || extMax_intMax == 0 && ext.getMaxUnit().getLevel() <= getMaxUnit().getLevel()))
    return SpatialRelation.WITHIN;
  return SpatialRelation.INTERSECTS;
}
 
Example 3
Source File: Geo3dShape.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Override
public SpatialRelation relate(Shape other) {
  int relationship;
  if (other instanceof Geo3dShape<?>) {
    relationship = relate((Geo3dShape<?>) other);
  } else if (other instanceof Rectangle) {
    relationship = relate((Rectangle) other);
  } else if (other instanceof Point) {
    relationship = relate((Point) other);
  } else {
    throw new RuntimeException("Unimplemented shape relationship determination: " + other.getClass());
  }

  switch (relationship) {
    case GeoArea.DISJOINT:
      return SpatialRelation.DISJOINT;
    case GeoArea.OVERLAPS:
      return (other instanceof Point ? SpatialRelation.CONTAINS : SpatialRelation.INTERSECTS);
    case GeoArea.CONTAINS:
      return (other instanceof Point ? SpatialRelation.CONTAINS : SpatialRelation.WITHIN);
    case GeoArea.WITHIN:
      return SpatialRelation.CONTAINS;
  }

  throw new RuntimeException("Undetermined shape relationship: " + relationship);
}
 
Example 4
Source File: PackedQuadPrefixTree.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
public boolean hasNext() {
  if (nextCell != null) {
    return true;
  }
  SpatialRelation rel;
  // loop until we're at the end of the quad tree or we hit a relation
  while (thisCell != null) {
    rel = thisCell.getShape().relate(shape);
    if (rel == SpatialRelation.DISJOINT) {
      thisCell = thisCell.nextCell(false);
    } else { // within || intersects || contains
      thisCell.setShapeRel(rel);
      nextCell = thisCell;
      if (rel == SpatialRelation.WITHIN) {
        thisCell.setLeaf();
        thisCell = thisCell.nextCell(false);
      } else {  // intersects || contains
        level = (short) (thisCell.getLevel());
        if (level == detailLevel || pruned(rel)) {
          thisCell.setLeaf();
          if (shape instanceof Point) {
            thisCell.setShapeRel(SpatialRelation.WITHIN);
            thisCell = null;
          } else {
            thisCell = thisCell.nextCell(false);
          }
          break;
        }
        thisCell = thisCell.nextCell(true);
      }
      break;
    }
  }
  return nextCell != null;
}
 
Example 5
Source File: NumberRangePrefixTree.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
public SpatialRelation relate(UnitNRShape lv) {
  assertDecoded();
  int cmp = comparePrefix(this, lv);
  if (cmp != 0)
    return SpatialRelation.DISJOINT;
  if (getLevel() > lv.getLevel())
    return SpatialRelation.WITHIN;
  return SpatialRelation.CONTAINS;//or equals
  //no INTERSECTS; that won't happen.
}
 
Example 6
Source File: NumberRangePrefixTree.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
public SpatialRelation relate(SpanUnitsNRShape spanShape) {
  assertDecoded();
  int startCmp = comparePrefix(spanShape.getMinUnit(), this);
  if (startCmp > 0) {//start comes after this cell
    return SpatialRelation.DISJOINT;
  }
  int endCmp = comparePrefix(spanShape.getMaxUnit(), this);
  if (endCmp < 0) {//end comes before this cell
    return SpatialRelation.DISJOINT;
  }
  int nrMinLevel = spanShape.getMinUnit().getLevel();
  int nrMaxLevel = spanShape.getMaxUnit().getLevel();
  if ((startCmp < 0 || startCmp == 0 && nrMinLevel <= getLevel())
      && (endCmp > 0 || endCmp == 0 && nrMaxLevel <= getLevel()))
    return SpatialRelation.WITHIN;//or equals
  //At this point it's Contains or Within.
  if (startCmp != 0 || endCmp != 0)
    return SpatialRelation.INTERSECTS;
  //if min or max Level is less, it might be on the equivalent edge.
  for (;nrMinLevel < getLevel(); nrMinLevel++) {
    if (getValAtLevel(nrMinLevel + 1) != 0)
      return SpatialRelation.INTERSECTS;
  }
  for (;nrMaxLevel < getLevel(); nrMaxLevel++) {
    if (getValAtLevel(nrMaxLevel + 1) != getNumSubCells(getShapeAtLevel(nrMaxLevel)) - 1)
      return SpatialRelation.INTERSECTS;
  }
  return SpatialRelation.CONTAINS;
}
 
Example 7
Source File: FilterToElasticHelper.java    From elasticgeo with GNU General Public License v3.0 5 votes vote down vote up
private void visitGeoShapeBinarySpatialOperator(BinarySpatialOperator filter, Expression e1, Expression e2,
                                                boolean swapped, Object extraData) {

    SpatialRelation shapeRelation;
    if (filter instanceof Disjoint) {
        shapeRelation = SpatialRelation.DISJOINT;
    } else if ((!swapped && filter instanceof Within) || (swapped && filter instanceof Contains)) {
        shapeRelation = SpatialRelation.WITHIN;
    } else if (filter instanceof Intersects || filter instanceof BBOX) {
        shapeRelation = SpatialRelation.INTERSECTS;
    } else {
        FilterToElastic.LOGGER.fine(filter.getClass().getSimpleName() 
                + " is unsupported for geo_shape types");
        shapeRelation = null;
        delegate.fullySupported = false;
    }

    if (shapeRelation != null) {
        e1.accept(delegate, extraData);
        key = (String) delegate.field;
        e2.accept(delegate, extraData);
        shapeBuilder = delegate.currentShapeBuilder;
    }

    if (shapeRelation != null && shapeBuilder != null) {
        delegate.queryBuilder = ImmutableMap.of("bool", ImmutableMap.of("must", MATCH_ALL, "filter",
                ImmutableMap.of("geo_shape", ImmutableMap.of(key,
                        ImmutableMap.of("shape", shapeBuilder, "relation", shapeRelation)))));
    } else {
        delegate.queryBuilder = MATCH_ALL;
    }
}
 
Example 8
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 9
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);
}