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

The following examples show how to use org.locationtech.spatial4j.shape.SpatialRelation#INTERSECTS . 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: 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 2
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 3
Source File: PackedQuadPrefixTree.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
private boolean pruned(SpatialRelation rel) {
  int leaves;
  if (rel == SpatialRelation.INTERSECTS && leafyPrune && level == detailLevel - 1) {
    for (leaves=0, pruneIter=thisCell.getNextLevelCells(shape); pruneIter.hasNext(); pruneIter.next(), ++leaves);
    return leaves == 4;
  }
  return false;
}
 
Example 4
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 5
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 6
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 7
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
}