Java Code Examples for org.locationtech.spatial4j.shape.SpatialRelation#CONTAINS
The following examples show how to use
org.locationtech.spatial4j.shape.SpatialRelation#CONTAINS .
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 |
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 |
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 |
@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: NumberRangePrefixTree.java From lucene-solr with Apache License 2.0 | 5 votes |
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 5
Source File: NumberRangePrefixTree.java From lucene-solr with Apache License 2.0 | 5 votes |
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 6
Source File: DefaultSpatialAlgebra.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public boolean ehCovers(Shape s1, Shape s2) { return SpatialRelation.CONTAINS == s1.relate(s2); }
Example 7
Source File: PackedQuadPrefixTree.java From lucene-solr with Apache License 2.0 | 4 votes |
@Override public Cell getCell(Point p, int level) { if (!robust) { // old method List<Cell> cells = new ArrayList<>(1); buildNotRobustly(xmid, ymid, 0, cells, 0x0L, ctx.getShapeFactory().pointXY(p.getX(), p.getY()), level); if (!cells.isEmpty()) { return cells.get(0);//note cells could be longer if p on edge } } double currentXmid = xmid; double currentYmid = ymid; double xp = p.getX(); double yp = p.getY(); long term = 0L; int levelLimit = level > maxLevels ? maxLevels : level; SpatialRelation rel = SpatialRelation.CONTAINS; for (int lvl = 0; lvl < levelLimit; lvl++){ int quad = battenberg(currentXmid, currentYmid, xp, yp); double halfWidth = levelW[lvl + 1]; double halfHeight = levelH[lvl + 1]; switch(quad){ case 0: currentXmid -= halfWidth; currentYmid += halfHeight; break; case 1: currentXmid += halfWidth; currentYmid += halfHeight; break; case 2: currentXmid -= halfWidth; currentYmid -= halfHeight; break; case 3: currentXmid += halfWidth; currentYmid -= halfHeight; break; default: } // set bits for next level term |= (((long)(quad))<<(64-((lvl + 1)<<1))); // increment level term = ((term>>>1)+1)<<1; } return new PackedQuadCell(term, rel); }
Example 8
Source File: QuadPrefixTree.java From lucene-solr with Apache License 2.0 | 4 votes |
@Override public Cell getCell(Point p, int level) { if (!robust) { // old method List<Cell> cells = new ArrayList<>(1); buildNotRobustly(xmid, ymid, 0, cells, new BytesRef(maxLevels+1), ctx.getShapeFactory().pointXY(p.getX(),p.getY()), level); if (!cells.isEmpty()) { return cells.get(0);//note cells could be longer if p on edge } } double currentXmid = xmid; double currentYmid = ymid; double xp = p.getX(); double yp = p.getY(); BytesRef str = new BytesRef(maxLevels+1); int levelLimit = level > maxLevels ? maxLevels : level; SpatialRelation rel = SpatialRelation.CONTAINS; for (int lvl = 0; lvl < levelLimit; lvl++){ int c = battenberg(currentXmid, currentYmid, xp, yp); double halfWidth = levelW[lvl + 1]; double halfHeight = levelH[lvl + 1]; switch(c){ case 0: currentXmid -= halfWidth; currentYmid += halfHeight; break; case 1: currentXmid += halfWidth; currentYmid += halfHeight; break; case 2: currentXmid -= halfWidth; currentYmid -= halfHeight; break; case 3: currentXmid += halfWidth; currentYmid -= halfHeight; break; default: } str.bytes[str.length++] = (byte)('A' + c); } return new QuadCell(str, rel); }
Example 9
Source File: SpatialOperation.java From lucene-solr with Apache License 2.0 | 4 votes |
@Override public boolean evaluate(Shape indexedShape, Shape queryShape) { return indexedShape.relate(queryShape) == SpatialRelation.CONTAINS || indexedShape.equals(queryShape); }